Get collision details from Rectangle.Intersects()

Posted by Daniel Ribeiro on Game Development See other posts from Game Development or by Daniel Ribeiro
Published on 2012-12-19T11:31:42Z Indexed on 2012/12/19 17:14 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

I have a Breakout game in which, at some point, I detect the collision between the ball and the paddle with something like this:

// Ball class
rectangle.Intersects(paddle.Rectangle);

Is there any way I can get the exact coordinates of the collision, or any details about it, with the current XNA API?

I thought of doing some basic calculations, such as comparing the exact coordinates of each object on the moment of the collision. It would look something like this:

// Ball class
if((rectangle.X - paddle.Rectangle.X) < (paddle.Rectangle.Width / 2))
    // Collision happened on the left side
else
    // Collision happened on the right side

But I'm not sure this is the correct way to do it.

Do you guys have any tips on maybe an engine I might have to use to achieve that? Or even good coding practices using this method?

© Game Development or respective owner

Related posts about XNA

Related posts about c#