dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
4.12k stars 252 forks source link

Objects fall through TriMesh terrain very easily #524

Open LPGhatguy opened 1 year ago

LPGhatguy commented 1 year ago

Hello!

We're working on a game that has terrain and physics objects. We're using TriMesh for representing that terrain currently. We have been having issues with objects falling through the terrain even without large velocities or forces being applied.

https://github.com/dimforge/rapier/assets/654598/bc0847ea-6bd4-4475-bff8-3f8d5d8fccba

Here is a video of one of the parts we've been experiencing this issue with. The rapier debug visualization is enabled.

The ground here is a trimesh with four vertices. The slab is a convex hull that is 2x0.03x2. Gravity is -9.81.

We've noticed this issue with slabs as thick as 10cm, but the issue happens very frequently with objects like this one.

The dragger used in the video moves the object slightly above the plane and rotates it before dropping it again. We can see from the debug visualization that there are correct contacts being computed on the corners, but that doesn't stop the entire object from falling through the terrain as it rotates.

sebcrozet commented 8 months ago

Sorry it took me so much time to start looking into this issue. I think two things need to happen to fix this:

  1. The internal-edges handler is not being conservative enough and is eliminating some contact that are essential to keep the rectangle above the floor. (I’m currently working on improving this).
  2. The prediction distance, that is currently a fixed value, needs to take into account the angular movement of the rigid-body. The point that is furthest from the existing collision with the floor ends up having at velocity that is large enough for it to tunnel through the ground.
LPGhatguy commented 8 months ago

Thank you for looking into this! We're still working on this project and still using rapier, so I'm very excited to test any changes that you come up with.

sebcrozet commented 7 months ago

Hey @LPGhatguy! I’ve got some news. Would you like to give https://github.com/dimforge/rapier/pull/625 a try? My recommendations are to:

Please let me know if that works or doesn’t. The work on improving triangle mesh behaviors has progressed quite a bit here, but there are still a few open questions. The thin-object on thin-terrain problem is generally quite challenging.

Thank you again for your patience!

raycar5 commented 7 months ago

Hi @sebcrozet I've been struggling with stability in collisions for my racing game where the track is a big trimesh and cars are convex decompositions, tried tuning a bunch of rapier parameters to no avail, sometimes after a collision the car would seemingly gain energy out of nowhere and go flying, I'm happy to report that after trying contact skin on the track and soft ccd on the car and playing with it for 15 minutes, the collisions seem a lot more realistic and I haven't had my car go flying yet, I'm cautiously optimistic since this seems to occur randomly but if it works, this is fantastic! I was starting to worry I'd have to drop rapier and move to a wrapped c++ physics engine, great job!

sebcrozet commented 7 months ago

@raycar5 Glad to hear that! Let me know if you still encounter a similar issue.