Search Unity

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:
    23
    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:
    136
    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:
    136
    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:
    136
    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:
    136
    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.
     
    chris_nocode likes this.
  10. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    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:
    60
    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:
    66
    Thanks for this! You helped us find a major issue we were having with our game Tabletop Simulator after upgrading from Unity 4.
     
  19. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    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...
     
  20. chris_nocode

    chris_nocode

    Joined:
    May 22, 2017
    Posts:
    2
    Excellent solution to my problem. It seemed as though the Auto Configure had my axis flipped, this caused my joint to pop up onto the other side of it's parent. I just added/removed minus symbols and the joint stayed in the correct coordinates.
     
  21. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Hinge joints is a nightmare to work with. :eek: I have several static solid arms that can be twisted through animation and it has several child objects. The last child is sort of a hanging device with a HingeJoint that should swing in the X axis but has child objects of its own (pls. refer to attached image for more info). The Connected Body I specified for the HingeJoint is an empty gameobject with a RigidBody that is Kinematic only and is a child of one of the solid arms. Every time I hit play, the arms and everything in it explodes! Also tried the suggested code above for the object that has a HingeJoint. But it doesn't seem to work for me. Would appreciate any tips or a link with a good tutorial on HingeJoints.
     

    Attached Files:

    Last edited: Jul 27, 2018
  22. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Partially solved my problem in Unity 2018.1.6. I just had to reverse the objects where I place the Hinge Joint script and who becomes the ConnectedBody with of course some minor configuration adjustments. That solved the object stability problem and prevented exploding. Now I have a new problem on how to make one object's axis rotation/swinging follow the Player's orientation as he moves. I posted more info here if anyone is willing to provide assistance.