# 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.9622486,"math_prob":0.65689415,"size":735,"snap":"2019-51-2020-05","text_gpt3_token_len":153,"char_repetition_ratio":0.11491108,"word_repetition_ratio":0.0,"special_character_ratio":0.19591837,"punctuation_ratio":0.09090909,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96611637,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-09T18:45:21Z\",\"WARC-Record-ID\":\"<urn:uuid:030eb93b-772c-454b-b6d7-4a28b0e68f44>\",\"Content-Length\":\"146925\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:67bf0c6b-2492-4c94-8956-eaf81a7e3e33>\",\"WARC-Concurrent-To\":\"<urn:uuid:a7c6ef70-afc6-4e56-8e23-84562e6d1294>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://gamedev.stackexchange.com/questions/38557/xna-2d-rotated-rectangle-collision-response\",\"WARC-Payload-Digest\":\"sha1:5N6QOR5YGHXQIZHFYLFWOLEP5FMLP4GB\",\"WARC-Block-Digest\":\"sha1:CNXY2MO7V7WRJHSDWU6XPVMZGFKMIEOX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540521378.25_warc_CC-MAIN-20191209173528-20191209201528-00156.warc.gz\"}"}