I've already implemented collision detection in my game loosely following this tutorial, which works great, but I realized there's one major flaw.
The player and the enemies are circles, while the obstacles can be either segments or polygons or circles.
Now, let's say I have
segment A from
point (100, 100) to
point (300, 100) and
segment B from
point (100, 200) to
point (300, 100), which means they form an acute angle, and player has it center in
point (100, 125), with a radius of 25.
If player starts moving right, it will eventually collide against segment B. My method
checkCollisions() will return a vector, but if I apply that vector on player, it will be moved up and left, and will overlap segment A.
If I call
checkCollisions() a second time, player will be pushed down and collide again with segment B, so recursive invocations aren't a solution. Any ideas?
Here's a picture to explain: The g->n vector direction is along the bisector of the two little vectors, but how do I find the length?