Hi everybody,
I’ve been a quiet reader within this community for a while now but now it seems that I’m facing an issue that can not be solved by reading other threads and I hope you can help me with it… ![]()
In my scene I’m using a configurable joint to rotate a gameobject that also contains a rigidbody around one axis by user input. To do so I increment or decrement a variable according to the user’s input and use this variable afterwards to set the joints target rotation. When there’s no more input that is meant to drive the joint it is locked again. I was able to prevent the problem (mentioned in other threads) of the joint snapping back to its original position when it gets locked by actualization of its “axis” and “secondary axis” property before finally locking it. To conclude: What I described works fine for me! Next I wanted to implement a variable that tells me how much degree the joint (the gameobject carrying the joint) has rotated totally. To do so I calculate a “delta Rotation” based on the rotation of the gameobject in the current and last update. The code I described so far looks like this…
void Update ()
{
if (Input.GetAxisRaw ("Horizontal") != 0)
{
rigidbody.WakeUp ();
joint.angularXMotion = ConfigurableJointMotion.Free;
joint.projectionAngle = 180f;
if (Input.GetAxisRaw ("Horizontal") > 0)
{
incTargetRotation += 0.2f;
joint.targetRotation = Quaternion.Euler (incTargetRotation, 0f, 0f);
}
if (Input.GetAxisRaw ("Horizontal") < 0)
{
incTargetRotation -= 0.2f;
joint.targetRotation = Quaternion.Euler (incTargetRotation, 0f, 0f);
}
}
else
{
joint.axis = joint.axis;
joint.secondaryAxis = joint.secondaryAxis;
joint.angularXMotion = ConfigurableJointMotion.Locked;
joint.projectionAngle = 0f;
incTargetRotation = 0f;
}
deltaRotation = Mathf.DeltaAngle (oldRotation, joint.transform.localEulerAngles.y);
totalRotation += deltaRotation;
oldRotation = joint.transform.localEulerAngles.y;
}
And here comes the Problem: When I check the value of “totalRotation” against that what’s shown in the inspector within comparable thresholds I always notice small discrepancies. For example: totalRotation saying -28.00153 when there’s -27.937 shown in the inspector. This is giving me a headache as I can’t figure out what the matter of those differences is or how I could prevent them. I would really appreciate any hint from you guys. ![]()
Best regards,
Mathias
