Search Unity

I figured out why joints are jittering...

Discussion in 'Physics' started by Ultroman, Apr 21, 2018.

  1. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    I've worked on a physics-driven ragdoll-like player character controller for a few months now, and have read just about everything on Unity/Physx joints I could find, and now I have a pretty stable character built with only configurable joints, most configured with "Enable collision" turned off, to make the colliders not affect his movement.

    Whenever I make him carry objects (rigidbodies) in his hands, the joint (with "Enable collision" set to false) between his hand and the object he carries, will jitter seemingly at random. Sometimes it works fine for 30 seconds straight, but suddenly it starts jittering, even when there is no movement in either object.

    The solution to my jittering hand-to-object-joint: Turn off the hand collider while the hand and the object are connected with the joint. It also works if I turn off the colliders on the object, with which his hands are able to collide.

    The jittering is completely gone! Butter smooth now. WTH? They should not be colliding with "Enable collision" turned off, and they don't look like they're colliding. It looks more like the connected anchor rapidly shifts back and forth between two different positions, which in turn affects the hand. But looking at the values on the joint, they're all stable while this is happening.

    Here's the full joint setup between the two objects. Any collapsed settings are left at default.



    I've tried to do a repro project, to file a bug report, but I can't make it jitter with simple setups. I have a full ragdoll, with loads of scripts for moving the hands, but I've painstakingly spent hours toggling all parts of my controller off and on in different configurations, to see if they had an effect on the jittering, but no. Only disabling one of the colliders, which should not be colliding anyway, removes the jittering.

    P.S.
    I hate these soft joints so much...why don't we have the choice of "hard" joints? You cannot build a mechanical object in Unity, with which players can interact, without it swinging out of its limits all the time.

    UPDATE:
    The colliders ARE the problem! Even with "Enable collision" set to false, when connecting the anchors and connectedBody, it still considers the colliders. When placing the object, say a weapon, in the hand of my player, if I do not turn off all the colliders on the hand, the weapon SOMETIMES gets pushed out of the colliders, and sits outside his hand. If I turn off all the colliders before setting the anchors, it always gets positioned correctly.
    Because of the first problem, with the jittering, I cannot reenable the hand colliders until the player lets go of the object.

    Everything is working fine now...except for the "Enable collision" flag on joints :)
     
    Last edited: Apr 21, 2018
  2. chris_schubert

    chris_schubert

    Joined:
    Jan 8, 2019
    Posts:
    28
    I'm having similar issues with the Configurable Joint. As far as I can tell, getting outside of the Ragdoll Wizard is a world of pain. I'm recursively creating animal ragdolls from the mesh bones, and on some animals it works absolutely perfectly, and others they jitter and explode. Absolutely same approach to jointing, but wildly different results - per animal. Meaning that the animal will either have 100% functional joints, or 100% non-functional joints. Never a bad joint on an otherwise good animal.
     
    Ultroman likes this.
  3. walaber_entertainment

    walaber_entertainment

    Joined:
    Jul 10, 2017
    Posts:
    30
    I was having a similar problem today with a ConfigurableJoint that's created at runtime when a specific collision occurs. by messing around in the inspector, I could get the joint to stop colliding if I disabled an involved collider, and then re-enabled it. So I tried doing that in my script, and it seems to be working...
    Code (CSharp):
    1.  
    2. // create the joint
    3. _createJoint();
    4.          
    5. // super duper Unity hack-sauce... I have to do this otherwise sometimes the colliders still try
    6. // to collide even after creating the joint. WTF.
    7. Collider[] cols = GetComponentsInChildren<Collider>();
    8. foreach(Collider col in cols)
    9. {
    10.    if (!col.isTrigger)
    11.    {
    12.       col.enabled = false;
    13.       col.enabled = true;
    14.    }
    15. }
     
    Ultroman likes this.
  4. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    That is absolutely terrible and horrible and works perfectly :) Thanks :D
    However, I prefer to be in full control of which colliders are messed with, so I'll just be checking with the colliders I know to affect, instead of the GetComponents call.
     
  5. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I had a similar issue. There was a capsule collider on a character controller that was causing the joint to be pushed away. I got around the issue by using:
    Physics.IgnoreCollision(colIiderInsideJoint, colliderOnAgent, true);
     
    Ultroman and snoutie like this.
  6. TheNerdyBoy

    TheNerdyBoy

    Joined:
    Dec 17, 2020
    Posts:
    2
    I had this problem with just making a door. Turns out I had the box collider on the door too big. I just made is smaller than the door and it works just fine
     
  7. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    Just my 2 cents as I just managed to fix my ConfigurableJoint jitter. The joint joins an object with my character that moves with mouse, and the movement was jittery.

    Unity has a checklist here: https://docs.unity3d.com/Manual/RagdollStability.html

    My issue was bullet nr 7 on the list, I needed to set the character and the object rigidbodies to similar masses. This completely changed the movement into fluid and fixed the jitter.
     
    Ultroman likes this.
  8. Ultroman

    Ultroman

    Joined:
    Mar 10, 2014
    Posts:
    110
    That's true and neat, but it's really annoying to have to negate the weight of something, just because it has to be connected to something.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is because this kind of physics engine (Physx) converges on solutions as an optimisation, so it does a few moves at a time. In the case of joints, it means similar masses do not fight each other.

    This is really common in physics engines.
     
  10. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    140
    This appears to be a bug with Enable collision, it remembers collider contacts at the time and doesn't reset them until you ghetto disable / re-enable the touching colliders.

    Use this in tandem with Physics.IgnoreCollision - don't trust Enable Collision field alone.