I read through the SAT algorithm and am using it mostly successfully for a platformer controller. However, I’m running into an edge case that I’m not sure how to deal with.
The player has some velocity which I use to translate the player in a direction. Then I use an
OverlapBox and extract the
ColliderDistance2D information from any collision. I then use the
.distance and the
.normal property to find a vector that pushes the player out of the collision. Something like this:
This works great in every situation that I’ve found except when approaching a corner diagonally. There reaches a point where instead of a wall to the right of the player pushing them out to the left, the minimum distance out of the wall is actually vertical instead- which is fine except for the case where a collision occurs after correcting vertically but wouldn’t if my algorithm “realized” that it was supposed to correct horizontally. I’ve illustrated this below, the situation is the player is jumping and sliding diagonally into a wall and eventually they reach a gap that is slightly too small for them to fit in:
Since the collision cannot be resolved the player stops moving right here.
I’m not sure I have a good solution to this. I notice that the minimum separation vector has a positive dot product with the velocity rather than negative which you would expect from a resistive force, so maybe I can do something with that information? My walls by the way are using a tilemap collider.