how to get the rotation of Configurable Joint?
how can you get the rotation of Configurable Joint as i know that there is HingeJoint.angle so is there something like that for Configurable Joint?
Answer by zukahara · Apr 16, 2020 at 12:59 PM
I'm also looking for this answer.
You can calculate the joint rotation easily if the Join Object and the connected Object have the same Axis, in other words they have the same Rotation at the beginning. With the following code you can get the current rotation(no guarantee, I'm a beginner in Unity):
GameObject jointObject;
GameObject connectedObject;
ConfigurableJoint cJ;
void Start()
{
jointObject = gameObject;
cJ = GetComponent<ConfigurableJoint>();
connectedObject = cJ.connectedBody.gameObject;
}
public Quaternion getJointRotation()
{
Quaternion r;
r = Quaternion.Inverse(connectedObject.transform.rotation) * jointObject.transform.rotation
}
Note:
This script should attach as component on the GameObject, that has the configurable joint.
The Configurable Joint must have the right Axis i.e. (x,y,z) = (1,0,0).
As you see, this method needs preconditions to work right.
I'm looking for a better solution.
Just as a note in case anyone else is looking at this: I had to use Quaternion.Inverse() on the result of r (line 17) to get an equivalent rotation to what I am using for SetTargetRotation.