Tuesday, July 14, 2015

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


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!)




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...