- Home /
Question by
MUG806 · Feb 15, 2021 at 12:53 PM ·
rigidbodyconfigurablejointangularvelocityconfigurable jointtargetrotation
Set ConfigurableJoint targetAngularVelocity towards targetRotation
I'm trying to get a stable configurable joint behaviour by setting the targetAngularVelocity to the value needed to move to the targetRotation in one frame. This makes the "damper" value much more useful. I have it working for the positional drive like so:
//set targetVelocity based on targetPosition:
joint.targetVelocity = ((joint.transform.TransformPoint(joint.anchor) + joint.WorldToJointSpace() * joint.targetPosition) - joint.connectedBody.transform.TransformPoint(joint.connectedAnchor)) / Time.fixedDeltaTime;
These are the extension methods used:
public static class JointExtensions {
public static Quaternion LocalToJointSpace(this ConfigurableJoint joint) {
Vector3 tertiaryAxis = Vector3.Cross(joint.axis, joint.secondaryAxis);
Vector3 actualSecondaryAxis = Vector3.Cross(tertiaryAxis, joint.axis);
return Quaternion.LookRotation(tertiaryAxis, actualSecondaryAxis);
}
public static Quaternion WorldToJointSpace(this ConfigurableJoint joint) {
return joint.LocalToJointSpace() * joint.transform.rotation;
}
}
This works great, but I need the same for rotation and can't get my head around the quaternion math. Any help would be hugely appreciated.
Comment