2D game collision response: SAT & minimum displacement along a given axis?

Posted by Archagon on Game Development See other posts from Game Development or by Archagon
Published on 2011-09-03T21:45:54Z Indexed on 2012/11/12 17:24 UTC
Read the original article Hit count: 340

I'm trying to implement a collision system in a 2D game I'm making. The separating axis theorem (as described by metanet's collision tutorial) seems like an efficient and robust way of handling collision detection, but I don't quite like the collision response method they use. By blindly displacing along the axis of least overlap, the algorithm simply ignores the previous position of the moving object, which means that it doesn't collide with the stationary object so much as it enters it and then bounces out.

Here's an example of a situation where this would matter:

Example

According to the SAT method described above, the rectangle would simply pop out of the triangle perpendicular to its hypotenuse:

SAT-Style Response

However, realistically, the rectangle should stop at the lower right corner of the triangle, as that would be the point of first collision if it were moving continuously along its displacement vector:

Realistic Response

Now, this might not actually matter during gameplay, but I'd love to know if there's a way of efficiently and generally attaining accurate displacements in this manner. I've been racking my brains over it for the past few days, and I don't want to give up yet!

(Cross-posted from StackOverflow, hope that's not against the rules!)

© Game Development or respective owner

Related posts about collision-detection

Related posts about physics