jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.79k stars 455 forks source link

Bounce on edge between two touching cubes #717

Closed nem0 closed 9 months ago

nem0 commented 1 year ago

Steps to reproduce:

  1. create two touching, static cubes with half extents =1
  2. create dynamic sphere with radius == 0.1 on top of one of the cubes image
  3. set velocity of the sphere to {5, 0, 0}
  4. run it
  5. observe that the sphere bounces up on the edge between the cubes bounce

Expected result: ball should not bounce on flat surface

jrouwe commented 1 year ago

What convex radius did you use? With the default convex radius the collision of the boxes will actually look like this:

image

So there will be a gap between the two boxes.

That said, Jolt doesn't currently do 'contact welding' between different objects, meaning that even though you do not see an edge here, there is one and the sphere can collide with it.

Note that this bug is very similar to https://github.com/godot-jolt/godot-jolt/issues/587 so you can look there for some more parameters you can tweak.

In any case, this is an area that I will be working on.

mihe commented 1 year ago

Note that this bug is very similar to godot-jolt/godot-jolt#587 so you can look there for some more parameters you can tweak.

Just to avoid any confusion, since I took some creative liberties when naming some of those settings, the settings highlighted in that issue are (in order) PhysicsSettings::mLinearCastThreshold, PhysicsSettings::mSpeculativeContactDistance and PhysicsSettings::mPenetrationSlop.

nem0 commented 1 year ago

What convex radius did you use? With the default convex radius the collision of the boxes will actually look like this:

Default radius. Also tried with different values, both smaller and bigger, results were even worse.

Tweaking values from https://github.com/godot-jolt/godot-jolt/issues/587 helped a bit, but it's still not perfect

jrouwe commented 10 months ago

Hello,

I submitted a potential fix for this issue (set BodyCreationSettings::mEnhancedInternalEdgeRemoval = true). I wrote some documentation for this new functionality here.

Please note that you'll have to make your boxes be part of the same body or else the algorithm will not work. Because of the way Jolt multithreads collision detection, collisions between different body pairs run on different threads, so it is very difficult to make this algorithm work across bodies.

jrouwe commented 10 months ago

I also posted a video of the results here: https://x.com/jrouwe/status/1748821475623088550?s=20