Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved HingeJoint2D has weird movements when there are limits

Discussion in 'Physics' started by voltcutter0, Oct 8, 2023.

  1. voltcutter0

    voltcutter0

    Joined:
    Mar 21, 2021
    Posts:
    8
    I have this 2D ragdoll that uses HingeJoint2D's to connect the limbs together. The limbs are all children of a gameobject which doesn't have any rigidbodies or physics components on it. The hinges have limits so the legs/arms/torso can't bend in unnatural ways.

    However, when the ragdoll is instantiated, it does this weird movement.

    Even after disabling the ragdoll's muscles, it still does the weird movement.

    I have already searched this problem on google but haven't found any good solutions. The most I have gotten is a forum post saying not to move rigidbodies using transform, which I am not doing, I am simply instantiating the object. I even tried to unparent the limbs from their parent gameobject, but it still did not solve the problem.

    This problem only occurs when the hinge joints have limits, so there aren't any weird movements when there are no limits on the hinge joints. What I expected when I used limits on the hinge joints was that the ragdoll would stay in the position that it was instantiated in, since the limits are correctly configured, but instead it does weird movements.
     
    Last edited: Oct 9, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,528
    And I guess you're using the default allowed solver iterations and have no increased it?

    How then can you use a HingeJoint2D on it as it requires two Rigidbody2D?

    The videos seem to indicate that when instantitated, it's already way outside of limits so you then have an open system that is trying to get itself back within limits and not trying to stand upright. The final video seems to back up that theory with all those rotations. Also, a HingeJoint2D is applying torque on both bodies so if one has lower mass, it'll achieve more rotation.

    All guesswork based upon seeing a few GIFS though.
     
  3. voltcutter0

    voltcutter0

    Joined:
    Mar 21, 2021
    Posts:
    8
    Sorry, I should have added more information.

    The limbs are connected using hinge joint 2ds. I think the limits are correct because the green line is inside the green angle gizmo. However, after I press the play button, the green line suddenly goes outside of the limits for some reason. After it goes outside the limits, it tries going back inside and eventually does which fixes it.
    And I was using the default iterations and didn't increase it. I did try increasing it, which did the weird thing faster but didn't entirely fix it.

    I'll try backing up and upgrading the project to another unity version (I am currently using 2019.4.40f1) and see if it helps
     
  4. voltcutter0

    voltcutter0

    Joined:
    Mar 21, 2021
    Posts:
    8
    Nevermind, I figured out why it kept doing that weird movement.

    Angle limits must not be greater than 180 or less than -180 or else it starts getting funky.
    For example, lower angle limit of -390 and upper angle limit of -330 is incorrect and will do weird movements.
    But lower angle limit of -30 and upper angle limit of 30 is correct and the hinge joint will not do weird movements.