Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

5.1 HingeJoint oddities

Discussion in 'Physics' started by Capn_Andy, Jun 10, 2015.

  1. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Hey everyone,

    After updating to Unity 5.1 I've noticed strange behaviour with hingejoints - after programatically attaching a hinge between two dynamic objects (that are sitting still/no gravity), they both "twitch" and start spinning around each other for a brief period of time (they'll settle, and this doesn't always happen).

    I'm also seeing the rotation of objects resetting or adjusting upon connection, though I see no transform adjustments anywhere, which makes me think it's some sort of contstraint bug or something...

    Maybe I'm missing something obvious though. Anyone else seeing problems?

    (my use case: little space man "grabs" a rock; player can move around and the rock swings around you as if it were tethered. I've got the anchor point at the spaceman (0,0,0 locally) and the hinge on the spaceman, with the connectedanchor point being at the local(relative) position of the object.)

    I also noticed that the "autoConfigureConnectedAnchor" option is setting the connected object to WorldCoordinates now instead of LocalCoordinates, which makes things warp around crazily too, if you have it enabled.
     
  2. Cybexx

    Cybexx

    Joined:
    Dec 4, 2008
    Posts:
    17
    This is from the Unity 5.1 release notes under Backwards Compatibility Breaking Changes

    Haven't tried this myself yet but it might be your culprit.
     
  3. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Yeah I caught that, thankfully we're not using limits, motors, or springs at all on this joint.
     
  4. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    103
    I can confirm that the Hinge joint is thoroughly spastic. autoConfigureConnectedAnchor now sets in world space which, when initialized, sends your object exploding through spacetime. Also I have found that if you build objects through script and apply hinge joints in one world angle, the results are completely different in another world angle. All my joints, slam 90 degrees to the left side, regardless of the hinge angle if the initial connected body object is set 90deg left. There are no settings in the hinge joint that either reset the rest position to local space, or are configurable. I will try to send some pics soon.
     
  5. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    103
    Is there a more verbose description for the HingeJoint changes? More has changed that just useLimits, and useSpring.
     
    Last edited: Jun 15, 2015
  6. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    103
    Ok I have solved my issue. Andy, if you are adding joints via script, be careful with the order that you assign the hingejoint variables. Mine was solved by adding the connected rigibody immediately after the line creating the hinge joint, and then changing the springs, limits, etc. Then the autoconnect could work a little smarter. Give that a shot. I dont know why that worked fine in the last build, but it looks like the way hingejoints are set up programmatically is a bit more strict.
     
    Knil likes this.
  7. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Ah yes -- if I attach the rigidbody first then set AutoAttach = true as the "final" configuration line, it totally solves all the problems. Thanks so much!
     
  8. Collrain

    Collrain

    Joined:
    Oct 27, 2012
    Posts:
    45
    I'm also having joint issues since upgrading to 5.1. I have a fairly simple script which creates a batch of joints and links them together to make a rope. Since the upgrade the hinge joints explode in all directions as soon as their created. The prefabs of the hingejoints aren't special, there just set to a specific axis, they use spring Damper and that's it. As the joints are created they have their connected rigidbody set the next joint in the line. Anyone know how to get multiple joints to connect together without exploding in 5.1?
     
  9. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    103
    That explosion typically comes from the automatic connection anchor being anchored in world space. Heres how to diagnose:
    • hit pause in the editor, and play your scene
    • go frame by frame until your chain is all together before the explosion
    • take note of the hinge joint properties
    • if your anchors are some Vector3 somewhere else in the level, this will cause them to explode.
    • Set those anchors manually via script.
    I have noticed that the hingejoint sets its own internal properties that you cant change, which is hugely annoying. This is typically when the autoConfigureConnectedAnchor bool is on. If you have problems with the joint, try disabling that the after you addcomponent the hingejoint.
     
  10. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    103
    here is an example of the order I had to script the joint to keep it from exploding.

    Note: I didnt use autoConfigureConnectedAnchor in my solution, but individual results may vary. The order of the script is the most important.

    if(!component.GetComponent(HingeJoint)){
    var jointh: HingeJoint = component.AddComponent(HingeJoint);
    jointh.connectedBody = GetComponent.<Rigidbody>();
    jointh.axis = Vector3.forward;
    jointh.anchor = Vector3(0, 0, 0);
    jointh.useLimits = true;
    jointh.limits.max = 1;
    jointh.limits.min = -1;
    }
     
  11. Collrain

    Collrain

    Joined:
    Oct 27, 2012
    Posts:
    45
    Ahh thanks RedRiverStudio, I'm at work at the moment so unable to test but that makes perfect sense as to why it would explode. I'll add in resetting the anchor to 0,0,0 in my script which will probably fix it as my order is similar to yours already. I'll update this post later once Iv tried it out.
     
  12. Collrain

    Collrain

    Joined:
    Oct 27, 2012
    Posts:
    45
    Yey, after a lot of trial and error my script is working again. Thanks RedRiverStudio it was down to the order of things like you said. I went right back to basics and just tried to get one hinge instantiated and connected another hinge to it. Changing the anchor to 0,0,0 was definitely the key, also making sure that the line was placed after the connected body.

    Thanks again
     
  13. Collrain

    Collrain

    Joined:
    Oct 27, 2012
    Posts:
    45
    Hmmm sadly I'm still having issues with multiple joints. I'm connecting lots of joints together to make a rope, if I make a short rope it seems to behave itself. But if the rope is more than about 25 joints long then it explodes after a bit of swinging. It seems like the weight of all the rope pieces starts to break the upper joints. Iv tried reducing the mass of the parts of the rope but seemed to have no effect. Anyone how I can achieve a rope made of many joints without it exploding?

    My joints are character joints but Iv tried with hinge joints and had the same effect.
    The current mass of each joint is 1, but iv tried 0.0001 and 10 and both seem the same.
     
  14. elehelvari

    elehelvari

    Joined:
    Apr 10, 2015
    Posts:
    18
    Hi All!

    I have a similar problem. Was searching for some solution when I found this thread.
    My physics setup works perfectly in Unity 4.6 then after moving to Unity 5 I am experiencing this one problem with the physics setup if the Auto Configure Connected Anchor is enabled.
    In Unity 4 it works perfectly, the object appears and hinges in the proper place but in Unity 5 the object snaps to world 0,0,0 when the Connected Body is set.
    The object with the hinge joint does not stay in place in Unity 5 as it does in Unit 4.6.

    I guess because of the this mentioned above:
    "I also noticed that the "autoConfigureConnectedAnchor" option is setting the connected object to WorldCoordinates now instead of LocalCoordinates, which makes things warp around crazily too, if you have it enabled."

    autoConfigureConnectedAnchor was so handy.
    Do I know have to have it disabled and set those values myself?
    Or is there any way to get the autoConfigureConnectedAnchor to work as it did before? :)
     
    Last edited: Sep 6, 2015
  15. elehelvari

    elehelvari

    Joined:
    Apr 10, 2015
    Posts:
    18
    Managed to solve the autoConfigureConnectedAnchor problem by disabling that and setting the Vector 3 myself, but I still have problem with the spring.
    In Unity 4.6 it all works perfectly, I can manually dial the spring target position and the object hinges nicely, but in Unity 5.1, changing the spring position does not behave so nicely. The object won't hinge, instead the physics starts blowing up.
     
  16. benni05

    benni05

    Joined:
    Mar 17, 2011
    Posts:
    58
    This solved it for me, thank you!
     
  17. BirthdayBoy

    BirthdayBoy

    Joined:
    Feb 11, 2014
    Posts:
    1
    I as well had a chain of objects hinged together to make a rope and was experiencing an explosion of my rigidbodies after my upgrade to Unity 5 which didn't happen in Unity 4.6.

    RedRiverStudio you solved my problem with: joint.anchor = Vector3.zero

    Thankyou I can now hang myself once again.
     
  18. Knil

    Knil

    Joined:
    Nov 13, 2013
    Posts:
    45
    Thanks for this! You helped us find a major issue we were having with our game Tabletop Simulator after upgrading from Unity 4.
     
  19. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    504
    Could anyone provide a sample scene or something, as I am working right on the same problem and can't find the right thing to tweak tho I'm tried a lot of solutions you guys suggested...