Search Unity

Has the behaviour of Hinge Joints changed from Unity 4 to 5?

Discussion in 'Unity 5 Pre-order Beta' started by Xoduz, Feb 16, 2015.

  1. Xoduz

    Xoduz

    Joined:
    Apr 6, 2013
    Posts:
    135
    In Unity 4.6.2f1 I used Hinge Joints to control the rotation of doors in my game, and I can open or close these doors by changing the Target Position value of a Hinge Joint to a specific angle in degrees. Set it to 90 and a door opens 90 degrees, set it to 0 and it closes, etc.

    In Unity 5.0 RC2 the same Hinge Joints on the same doors only seem to accept a Target Position value between 0 or 1...

    What gives? Has the behaviour for these joints changed from Unity 4.x to 5.x? If so I'd appreciate some tips on how to achieve the same result as with the previous version of Unity.
     
  2. Xoduz

    Xoduz

    Joined:
    Apr 6, 2013
    Posts:
    135
    Bug reported about this with Issue ID 674262, as the functionality of the Hinge Joint -> Spring -> Target Position property in Unity 5.0 RC2 does not seem to conform to how the Unity documentation (neither 4.x or 5 beta docs) says it should work, and said functionality has also changed from Unity 4.6.2f1 with no mention being made of this in the Unity 5 beta release notes (or anywhere else that I could see).
     
  3. Xoduz

    Xoduz

    Joined:
    Apr 6, 2013
    Posts:
    135
    From the Unity 5.0 RC3 release notes:
    Yep, it's now once again possible to enter values for targetPosition in degrees, as before. However, the functionality still seems to have changed from earlier. I'll give an example:

    On a simple 3D Cube, with a HingeJoint & Rigidbody attached, with settings for HingeJoint being "Spring 90", "Damper 0" and "TargetPosition 0", the 3D cube will rotate by 90 degrees around the Hinge axis if I manually enter "90" as value for the spring's TargetPosition in the Inspector while Unity is in play mode. If I a bit later change the value for TargetPosition back to 0 (still in Inspector), the cube will rotate back to it's starting position.

    Next, let's try to do this exact same procedure through a script attached to the cube, initiated by a player clicking on the cube:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. private var _hinge : HingeJoint;
    4.  
    5. function Start()
    6. {
    7.     _hinge = GetComponent( HingeJoint );
    8. }
    9.  
    10. function OnMouseDown()
    11. {
    12.     _hinge.spring.targetPosition = 90; // Rotates cube 90 degrees
    13.     yield WaitForSeconds( 5 );
    14.     _hinge.spring.targetPosition = 0; // Does nothing??
    15. }
    In this case, nothing happens when we sets the targetPosition to 0 after a little while. In Unity 4.x this same script will reset the cube's rotation to it's original rotation when targetPosition is set to 0, but that doesn't happen in Unity 5.0 RC3+.

    Am I missing something really obvious about how these hinges are supposed to work? Or about why they work differently when modified through the Inspector versus through scripts?