Hey there!
I'm trying to make a simple 3D physics engine. Everything is working pretty well, except for this one problem I just can't figure out: when objects hang over the edge of another object even slightly they will build momentum until they eventually slide off:
The cause is pretty simple. In the example the box has physics enabled, while the platform is static. When the box lands on the center of the platform, it will generate the following normal and contacts:
![](https://uploads.gamedev.net/forums/monthly_2020_09/2d1a3f99abf44aa0ba26a6c63768feca.Example2.png)
Each of the contacts will generate angular velocity (as shown by the arrows). Since both contacts are equal distance away from the center of mass, their torques are exactly opposite and cancel each other out. However, when an objects hangs over an edge, the following happens:
![](https://uploads.gamedev.net/forums/monthly_2020_09/f72ec16d26b44b04a2fadfdc3ab2293c.Example1.png)
The right contact is now closes to the center of mass than the left one, meaning it creates less torque. The total angular velocity therefor becomes non-zero and the box will rotate to the right, and the collision normal along with it:
![](https://uploads.gamedev.net/forums/monthly_2020_09/9f2e1fa1b5de4d0fa9d76763498a19dc.Example3.png)
The box will be pushed out along the collision normal, causing it to build momentum to the right and eventually slide of.
This obviously isn't supposed to happen, but I don't know how to fix this. What am I missing? My code is a mess right now, so I'm kind of afraid to share it, but it can be found here.
Thanks for reading and have a nice day!
(Note: I made a post about this same problem a couple of days ago. However, I now know more about the specifics of the problem, which has caused my question to change.)