# XNA 2D Rotated Rectangle Collision Response

I am using Rotated Rectangles which collide using the Separating Axis Theorem and they work perfectly fine for collision detection using Intersects and Contains.

However, I am starting to use faster objects in my game now and there is the issue of the two object overlapping during collision due to their higher velocities. I would like to do a collision response where I find out how much they are overlapping in the X and Y and put position them outside of each other.

I would like to use something like this: http://go.colorize.net/xna/2d_collision_response_xna/index.html.

But I am having some issues trying to adapt this to handle the rotation of the bounds.

Is this possible? Are there any resources out there that I can look at?

• Try enabling continuous collision detection. – ClassicThunder Oct 8 '12 at 19:36
• All collision detection is handled by me. I don't have a continuous collision detection option. – Kyle Uithoven Oct 8 '12 at 19:39
• My bad I misread faster as farseer as in the physics engine. – ClassicThunder Oct 8 '12 at 19:42

I found a version of the Separating Axis theorem that includes the creation of a minimum translation vector (MTV), the use of this vector allows me to place the objects that are colliding outside of the collision and generate physics properties based on the collision.

http://www.metanetsoftware.com/technique/tutorialA.html

The simple, but resource consuming solution is to calculate multiple states in a single update. Normally we calculate the positions of the object 'A' once every update. So in 3 consecutive updates, we're gonna calculate P_A, P_A' and P_A''. This is fine for most game engines, but as velocities get higher, and / or objects get smaller, the difference between P_A and P_A' may be too big to notice a collision that actually occurs between the two.

However, nobody says that we have to calculate exactly once the new position of 'A' in each update. You get the elapsed game time, and use fractions of it to calculate multiple position between P_A and P_A': P_A1, P_A2, P_A3 etc. Then you do it for the other object ('B') as well: P_B1, P_B2, P_B3 etc. Once you calculated P_A1 and P_B1, you do a collision detection with those positions. If there's no collision, you do it with P_A2 and P_B2, and so on.

Yes, this can slow down your game if you have lots of objects. If you run into performance issues, then you might have to dig deep into mathematics, I'm afraid. I'm actually representing rotated rectangles as polygons in my engine. You might want to look into Polygon collision detection, and the point-in-polygon algorithm. Maybe you can find some useful ideas.

• So, you are proposing that instead of calculating intersection depth, that I instead, calculate multiple states. This is what I am currently trying to get away from. I need the intersection depth to calculate the collision response and also for calculating a deflection velocity. – Kyle Uithoven Oct 10 '12 at 1:53
• @KyleUithoven Well, as I said, it's "the simple, but resource consuming solution". It works and it does what you'd expect. I'm sure there are better solutions, but it's still better than nothing :-) – Marton Oct 10 '12 at 6:16
• I don't think you understand what I am saying. I already do this solution, it does not provide an intersection depth, and does not do what I am asking for in the question. – Kyle Uithoven Oct 10 '12 at 18:53
• @KyleUithoven Okay, I just assumed this was your problem.("However, I am starting to use faster objects in my game now and there is the issue of the two object overlapping during collision due to their higher velocities.") – Marton Oct 11 '12 at 5:38
• That is my problem, which is why I am looking to get the intersection depth. If I can get the intersection depth I can get a minimum translation vector and use that to place them outside of each other and create a velocity vector based on the collision. – Kyle Uithoven Oct 11 '12 at 21:29