I am trying to simulate the behaviour of a rigid body, for example a cube, while it settles on a flat surface. Let's say it lends on an edge or even on a corner, and now it has to settle and remain on the surface. I am modeling this by rotating the body around contact line or a contact point, but I have a problem when the body needs to stop moving.
At the moment, the effect I got is that when it lands on the surface, it is still not perfectly aligned with it, so in my collision detection I am detecting that I still have just one contact point, so I am trying to generate rotations around this contact point.
After this, another edge or corner becomes the contact point, so it starts to rotate around that one and soon things become frantic; the cube is dancing wildly and not settling.
To explain a bit more, every frame I am collecting data about which of the corners is closest to the surface of interest and storing this data in a C++ type, std::vector
. If I have a result that all four points(corners) are at the same distance, I put them all inside a vector. After the collision detection method is called inside my physics engine code, I try to resolve it, and I do this by returning the data about collision points and corners etc.
Any advice on how to approach this particular problem?