Search code examples
c#mathxnacollision-detection

C# maths, collision detection, xna


Im doing collision detection in a game. All the surfaces are orthagonal so I only need to determine which face of an obstacle my moving object has collided with. I have the rectangle defining the intersection of the two objects and the vector representing the moving objects speed and direction of movement.

I reckon I need to translate the intersection rectangle along my moving objects vector until the intersection becomes a line, then I'll know which face was collided with 1st.

I have no idea how to do this mathematically of programatically however enter image description here

enter image description here


Solution

  • Actually I may have figured it out...

    • Find the point on the intersection rectangle that isnt on the objects rectangle

    • draw a line from there in the vectors direction

    • whatever side it intersects with is the side that collided 1st