Test intersection of two game objects (Phaser 3)

You can do this without physics. You copy the bounds of the game objects to rectangles and then use the Phaser.Geom.Intersects methods. Recycling the rectangles is efficient.

Most game objects have two boundaries, possibly distinct: Phaser.GameObjects.Components.GetBounds#getBounds() and Phaser.Display.Bounds.GetBounds(). If you’re not interested in transforms then GetBounds() is faster.

Phaser.Geom.Intersects.RectangleToRectangle() tells you whether the rectangles intersect at all, and Phaser.Geom.Intersects.GetRectangleIntersection() calculates the intersection area, if any.

2 Likes

@samme you are a genius man. I hope you know that. Half of my game is only functional because of some of the posts you’ve been involved in.

1 Like