I'm doing collision detection for a game, The levels are randomly generated from blocks each with its own bounding box. My collision detection is ok except sometimes, the player ship can collide with 2 or more blocks at the same time and I need to work out which one it hit 1st.
Ive already worked out that If I find the corner of the ship bounding box thats in its movement direction, and then draw a line in the opposite direction of the ships movement vector from that corner (red line on diagram), the intersection point thats furthest away on that line will be on the 1st box hit. I just don't know how to program that logic!
What I have to work with
- List of the bounding boxes (Rectangles) collided with
- ships movement (Vector2)
- Ships bounding box(Reactangle)
