Search code examples
c#xna2dcollision-detection

Trouble with Rectangles overlapping instead of touching XNA 4.0


I'm making the skeleton for the typical BubbleShooter game in XNA, and I'm having issues with my collision detection algorithm, which is explained in the picture here

Depending on where the colliding Rectangle position is at the moment of collision, a new position is assigned to the colliding Bubble.

The issue appears when I shoot a bubble and this happens at the moment of collision. I have run the debug step by step, and the moment when the collision happens is exactly like the picture, so my algorithm fails.
I tried to post the images directly, but it seems I can't since I'm still a new user here. Sorry about that.

Is there a way I can detect exactly when the boundaries of the Rectangles touch each other?


Solution

  • You can perform a per pixel collision instead, it is explained here:

    Click here