FixedJoint

This commit is contained in:
mischa 2024-01-24 15:15:18 +01:00
parent 6b88d43b3a
commit 43018e06b3

View File

@ -258,8 +258,26 @@ public static void MoveFixedJoints(GameObject source, GameObject destination)
FixedJoint[] sourceJoints = source.GetComponentsInChildren<FixedJoint>();
foreach (FixedJoint sourceJoint in sourceJoints)
{
// TODO not supported yet
Debug.LogError($"Prediction: {source.name} has a FixedJoint on {sourceJoint.name}. Prediction does not support joints yet, this won't work properly.");
// copy the relative transform:
// if joint is on root, it returns destination root.
// if joint is on a child, it creates and returns a child on destination.
GameObject target = CopyRelativeTransform(source, sourceJoint.transform, destination);
FixedJoint jointCopy = target.AddComponent<FixedJoint>();
// apply settings, in alphabetical order
jointCopy.anchor = sourceJoint.anchor;
jointCopy.autoConfigureConnectedAnchor = sourceJoint.autoConfigureConnectedAnchor;
jointCopy.axis = sourceJoint.axis;
jointCopy.breakForce = sourceJoint.breakForce;
jointCopy.breakTorque = sourceJoint.breakTorque;
jointCopy.connectedAnchor = sourceJoint.connectedAnchor;
jointCopy.connectedBody = sourceJoint.connectedBody;
jointCopy.connectedArticulationBody = sourceJoint.connectedArticulationBody;
jointCopy.connectedMassScale = sourceJoint.connectedMassScale;
jointCopy.enableCollision = sourceJoint.enableCollision;
jointCopy.enablePreprocessing = sourceJoint.enablePreprocessing;
jointCopy.massScale = sourceJoint.massScale;
GameObject.Destroy(sourceJoint);
}
}