Hi, I currently writing my own Hinge Joint implementation (don't ask me why, I have my reasons). So far i works pretty well, I'm just struggling with my old nemesis Quaternions when trying to write a method that returns the Hinge Joint Angle. My code so far looks like this:
void Start ()
thisBody = GetComponent<Rigidbody>();
thisJoint = GetComponent<HingeJoint>();
otherBody = thisJoint.connectedBody;
origRot = Quaternion.Inverse(thisBody.rotation)*otherBody.rotation;
Quaternion betweenBodies = Quaternion.Inverse(otherBody.rotation) * thisBody.rotation;
Quaternion difToOrig = Quaternion.Inverse(origRot) * betweenBodies;
difToOrig.ToAngleAxis(out angle, out axis);
I'm trying to compare the current rotation to the rotation at the start (rotation is measured as the difference in orientation between the two bodies). Since this orientation can only change around the hinge axis over time I use Quaternion.ToAngleAxis to get the current hinge angle (I hereby assume that the angle at the start is always 0).
When I compare the values to unitys builtin hingejoint.angle I match the absoulute values, but for some reasons my method always returns positive values for the angle.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
82 People are following this question.
Check if rotation (only on Y axis) of some object toward another is finshed?
Creating a multiple part turret what locks onto certain axis.
Rotation from AngleAxis() ToAngleAxis() flips back and forth
Set the rotation reference to an direction
Limiting rotation of object in script