Physics Joints with Prediction

Adding a joint during runtime seems to create a lot of weird behavior when there is any latency added (runs as expected if Client send/recv delay is 0).

Most likely it has to do with the joint not being a predicted entity (both of the connected entities of the joint are properly predicted).

I currently create the joint in the following way:

var joint = PhysicsJoint.CreateFixed(rbTf, new BodyFrame());
var jointEntity = ecb.CreateEntity();
ecb.SetName(jointEntity, $"FixedJoint {e.EntityA.Index} - {e.EntityB.Index}");
ecb.AddComponent(jointEntity, new PhysicsConstrainedBodyPair(e.EntityA, e.EntityB, false));
ecb.AddComponent(jointEntity, joint);
ecb.AddComponent(jointEntity, physicsWorldIndexType);

I’m probably missing a few components that the joint is properly working in the prediction loop.

Is it currently supported to create joints at runtime for a networked physics-based game running predictions?

I typically would have all the joints I would possibly need already instantiated. For any joint you aren’t currently using, you can set bodyB of the PhysicsConstrainedBodyPair to the joint entity itself (setting it to Entity.Null constrains it to world space, while setting it to an entity without PhysicsBody components causes the joint to be ignored). This way you can effectively enable and disable joints without making structural changes, making it easier to incorporate joints into prediction logic.

1 Like

Creating a joint on the fly like that is not replicated.
The physics entities are but the joint constraint itself it is not, unless it is part of a prefab,
If you create a joint dynamically in game, the logic that create the joint must be in the prediction loop and performed the same by both client and server