Weird behavior with chain made of pin joints
Describe the bug
There's some weird behavior with my chain test as soon as I add a cube. Somehow a sphere doesn't seem to be a problem.
https://streamable.com/05lskm (i'm not spinning it in the first part, just moving a bit and then stopping) other physics engines don't have a problem with it.
https://streamable.com/esknn1 (i'm only moving at the beginning)
To Reproduce
Move around in test project with WASD, then stop moving. The chain goes crazy. Delete the cube, the chain works as expected.
Duplicate the Player node and move it to the side, same problem + a weird offset is added to the first joint.
Expected behavior
See second part of the first video.
Environment:
- OS: Windows
- Version: 0.8.19 (videos were recorded with a previous version but the problem is still there with 0.8.19)
- Godot Version: 4.5.1
- Type: simd 3d
Example project(zip)
Tested locally, issue was that the player cylinder has connected a chain that was self intersecting the cylinder, but since the joints had disable collision enabled, only later parts of the chain would interact with the player cylinder, making it go in a loop (intersection resolution would separate the object, but pin joint would bring them together). Solution is either to not allow the big cylinder to self intersect with chain, or to disallow the join disable intersection between nodes.
Allowing the nodes connected by the joints to collide fixed the weird chain behavior (though I don't see why the cube makes any difference, or why exclude_nodes_from_collision wouldn't be supported), but duplicating the "Player" chain still creates a gap between the topmost chain link and the top cylinder:
https://streamable.com/dsnz5k
Also not sure why the cube makes a difference, exclude_nodes_from_collision is supported, just that it allows bodies to cross one another (eg. to go through each other), so it's possible that one object intersecting another might have another joint connected that wanted to pull it closer but it would rather intersect, thats my guess. Eg.:
A -> B -> C
A connected to B (assume they are intersecting and B is totally inside A).
B connected to C ( since B is totally inside A, part of C is also inside A. The physics engine will now try to both: separate C from A, and pull C together to B).
Another thing that might cause instability is the different mass ratio of objects.
Will try it again locally and see if I find if we set something wrong on our side (in Godot-Rapier). If not, it might be an upstream issue (in Rapier)
I'm not sure there is much we can do from godot-rapier side, it seems to be a stability issue in rapier, you can open instead an issue on rapier repo side. Also, the video expired, put it instead inside the github issue if possible.
@Damnae you might be interested in multibody joints also, I'm adding them to godot-rapier (read more about it below). Not 100% sure if it will fix your issue or not though: https://rapier.rs/docs/user_guides/rust/joint_constraints/#multibodies
https://github.com/user-attachments/assets/2b32781d-ce02-49c4-be4d-37f92809a334