Differences
This shows you the differences between two versions of the page.
Next revision
|
Previous revision
Next revision
Both sides next revision
|
hingejoint [2021/04/28 17:30] 73.95.178.156 created |
hingejoint [2021/04/30 16:31] 151.202.25.206 |
====== HingeJoint ====== | ====== HingeJoint ====== |
* ''HingeJoint.angle'' is relative to the <sup>[//[[:wiki:tag:research-needed|research needed]]//]</sup> | |
| A common misconception ((Or at least, a misconception held by me, the author of this page)) is that ''HingeJoint'' constrains the ''rotation'' or ''localRotation'' of the ''Transform'' that it is attached to. This is not strictly true. **''HingeJoint'' only constrains the relative rotation between its own ''RigidBody'' and the ''Rigidbody'' in the ''ConnectedBody'' field**. |
| |
| Another common misconception is that ''HingeJoint.angle'' and ''HingJoint.axis'' represent the ''rotation'' of the ''Transform'' that it is attached to. This is also not strictly true. That is, **''Quaternion.AngleAxis(hingeJoint.angle, hingeJoint.axis)'' does not necessarily equal ''hingeJoint.transform.rotation'' or ''hingeJoint.transform.localRotation''**. |
| |
| These two misconceptions, taken together, can make a ''HingeJoint'' behave quite differently from what you might expect. |
| |
| To quote the [[https://docs.unity3d.com/ScriptReference/HingeJoint-angle.html|official docs]]: |
| |
| > The rest angle between the bodies is always zero at the beginning of the simulation. |
| |
| The consequence of this is that ''HingeJoint.angle'' does not depend on the starting orientation of either the joint's ''RigidBody'' or the connected ''RigidBody''. And because ''HingeJoint.limits'' represents limits on ''HingeJoint.angle'', the limits are also independent of any starting orientation of the bodies. |
| |
| An example: Consider a ''GameObject'' with rotation ''(0, 0, 0)'' and a ''HingeJoint'' on the x-axis with limits of ''[-90, 90]''. When played as-is, this ''GameObject'' will be free to rotate between ''(-90, 0, 0)'' and ''(90, 0, 0)''. However, if you rotate this ''GameObject'' in the editor such that it starts with rotation ''(90, 0, 0)'' and play it, the ''GameObject'' will then be free to rotate between ''(0, 0, 0)'' and ''(180, 0, 0)'' - even though the angle limits have not changed. |