Hello. I am trying to implement my collision engine for a 2d platformer. I want it to support vector geometry, such as polygons and slopes of different angles and shapes. For a pair of two polygons i use Separating axis theorem to find the minimum translation vector that is needed to be added to the body position to separate them. However, i've ran into following problems:
At first, i dont know how to handle collisions with multiple bodies. If i translete the moving body by every minimum translation vector i found by colliding it with each static polygon, the total translation result may appear to be too long or too short.
The second problem appears in some situations when i alter the velocity of the moving body accordingly to the collision data. For example, in such situations, as shown in the picture below.
The body (blue rectangle) is moving with velocity V and penertates into a wall composed out of two red rectangles. While processing collision with the leftmost red rectangle, the normal is found by smallest penetration axis, it points up. I subtract the normal, multipled by the dot product of normal end velocity, from the body velocity vector. This is OK. However, in the case of rightmost red rectangle, the horisontal penetration (X) appears to be smaller than vertical penetration (Y) and the collision normal is considered to be horisontal. It makes the body to stop, while it had to slide along the wall.
I found several solutions to this problem, such as:
- Make the world out of line segment loops without inner edges.
- Make the corners of the moving bodies, static obstacles or both, smooth and round.
I also tried continuous collision detection, but ran into a similar problem where bodies were colliding with the corners of static obstacles.
Although i can solve this problem by rounding the moving shapes, i still wonder how the similar problem is solved in modern 3D physics engines and other 2D games.
I also still dont know, how to move the body out to solve its penetration into multiple obstacles.
Thank you if you can help.