I'm trying to use a ConfigurableJoint
(based on Nvidia's 9xD6Joint) to manipulate a Rigidbody
the player is holding. I have an issue with setting the spring part of the joint correctly. This is how the joint I'm using is configured:
_joint.autoConfigureConnectedAnchor = false;
_joint.connectedAnchor = Vector3.zero;
_joint.enableCollision = true;
_joint.rotationDriveMode = RotationDriveMode.Slerp; // using slerp rotation
_joint.xMotion = ConfigurableJointMotion.Free;
_joint.yMotion = ConfigurableJointMotion.Free;
_joint.zMotion = ConfigurableJointMotion.Free;
_joint.angularXMotion = ConfigurableJointMotion.Free;
_joint.angularYMotion = ConfigurableJointMotion.Free;
_joint.angularZMotion = ConfigurableJointMotion.Free;
Here is how I try to set the target rotation of the joint:
var playerRotation = transform.rotation;
var targetRotation = Quaternion.Inverse(playerRotation) * _targetRotation;
_joint.targetRotation = _targetRotation;
_targetRotation
is the rotation I'm trying to achieve, in world space.
The problem is that the rotation of the connected body doesn't match up with the _targetRotation
. There is always some offset, that rotates the connected body at an angle relative to the _targetRotation
. Once connected the offset stays consistent. What's even more confusing to me is that the offset seems to be based on the initial rotation of the connected body. This means that the same _targetRotation
will result in different connected body rotation if the connected body's rotation was different when connecting it to the joint.
Also the multiplication by Quaternion.Inverse(playerRotation)
is there only to make the rotation relative to the player, but the same problem occurs when this step is ommited.