HingeJoint

This commit is contained in:
mischa 2024-01-24 15:19:32 +01:00
parent 43018e06b3
commit 4dec04c78b

View File

@ -288,8 +288,34 @@ public static void MoveHingeJoints(GameObject source, GameObject destination)
HingeJoint[] sourceJoints = source.GetComponentsInChildren<HingeJoint>();
foreach (HingeJoint sourceJoint in sourceJoints)
{
// TODO not supported yet
Debug.LogError($"Prediction: {source.name} has a HingeJoint 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);
HingeJoint jointCopy = target.AddComponent<HingeJoint>();
// 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.extendedLimits = sourceJoint.extendedLimits;
jointCopy.limits = sourceJoint.limits;
jointCopy.massScale = sourceJoint.massScale;
jointCopy.motor = sourceJoint.motor;
jointCopy.spring = sourceJoint.spring;
jointCopy.useAcceleration = sourceJoint.useAcceleration;
jointCopy.useLimits = sourceJoint.useLimits;
jointCopy.useMotor = sourceJoint.useMotor;
jointCopy.useSpring = sourceJoint.useSpring;
GameObject.Destroy(sourceJoint);
}
}