Topic was automatically imported from the old Question2Answer platform.
Asked By
gazer500
I want to connect two rigid bodies together using the PinJoint2D node, but I want it to work so that one object only moves if the other is moving, and it moves/rotates the exact same way as that object. Unity has something like this called a FixedJoint, and I want to know if there’s a way to implement something similar in Godot.
Idk if Godot has something similar, but can’t you just use parenting? Even the Unity docs say that it’s just like parenting, but using physics instead: Unity - Manual: Fixed Joint component reference
Bernard Cloutier | 2021-11-25 20:11
We kinda can use parenting to simulate fixedjoint, we can set staticbody2D as the child of rigidbody2D, and the staticbody acts as it is welded to rigidbody2D, but we can’t weld rigidbody2D to another rigidbody2D by setting it as the child of rigidbody2D ):
I’d like to share, how to create fixed joint in godot.
Obviously ,we can’t just parent a rigidbody to another rigidbody for creating fixed joint.
a child rigidbody will lost rigidbody property.
We can create compound object. Actually, it is a rigidbody with multiple collision shape.
example.
-Rigid_A
|->Collision_Shape_A
|----->Mesh_A
|->Collision_Shape_B
|----->Mesh_B
On runtime, we can just move only collision_shape and Mesh of rigidbody B to be under Rigidbody A.
The best approach is to create a compound object, as mentioned earlier. However, if you need to connect objects dynamically at runtime or create destructible connections, you can use joints for smaller structures.
Here are a few viable options:
option 1: pinJoint. using two pinjoint, where each one is child of one rigidbody and node a is their parent node
option 2: Generic6DOFJoint
option 3: Rapier fixed joint. The Rapier physics engine includes a “FixedJoint” node. While it is more stable than the others Joints, it still does not provide a perfectly connection.
However, keep in mind that real-time physics simulation is iterative. Even with a dedicated FixedJoint, a long chain of connected RigidBodies will eventually suffer from precision loss, causing the structure to become “jiggly,” flex like jelly, or violently shake apart. For massive setups, always stick to the compound object method.
Rapier Bug: There is a Bug in Rapier where you cannot just change Node A and Node B properties via code at runtime—the script only processes them once inside the _ready() function. If you are changing the properties of node A and node B via code, you must manually call the _rebuild() method after.