Search Unity

Question Animation Rigging IK Jitter/Shaking WITH VIDEO

Discussion in 'Animation Rigging' started by LightPat02, Sep 23, 2022.

  1. LightPat02

    LightPat02

    Joined:
    Jan 27, 2020
    Posts:
    3
    I'm using a two bone IK Constraint in the Unity Animation Rigging package (ver. 1.0.3) to position my arm on a gun. See the YouTube video link if you want to see the jitter:


    A couple things to note here:
    1. the gun is not moving, so the IK target isn't either.
    2. this object is having root motion applied to it via fixedUpdate, however, even when using regular root motion, or not having any root motion at all, this issue is still there.
    3. when I apply an avatar mask that does not animate the arms, the issue is still there, so I do not believe that the base animation is the problem here. I have also tried setting the animator speed to 0 and still get jitter.

    Thanks in advance for your help
     
  2. LightPat02

    LightPat02

    Joined:
    Jan 27, 2020
    Posts:
    3
    The solution was that the character was too far away from world 0
     
    laurentlavigne likes this.
  3. DanielRiches

    DanielRiches

    Joined:
    Nov 23, 2019
    Posts:
    166
    Check your characters overall scale, I had a problem where my character was physically jittering like that at 0.1 scale, so I increased the scale to 0.2 and it stops the jittering. Something about having smaller scale characters makes the subtle movements of animations more pronounced for some reason, maybe a floating point accuracy thing but i'm not sure.
     
  4. LightPat02

    LightPat02

    Joined:
    Jan 27, 2020
    Posts:
    3
    "maybe a floating point accuracy thing"

    I'm pretty sure this is it. Also the scale was 1 in my video. Regardless I'm sure that can be another problem with it.

    Another problem I ran into was from using a humanoid avatar, and not also assigning the hand targets using OnAnimatorIK(). I made a script that manages the weight of the humanoid IK to match the weight of the Animation Rigging IK. That fixed a "sliding" problem with my IKs that made it look like the hands were not fully reaching their IK targets (this was not part of the original problem just thought I'd put it here).

    Here's the code:
    Code (CSharp):
    1. [Header("OnAnimatorIK")]
    2.         public Rig rightArmRig;
    3.         public Rig leftArmRig;
    4.         public bool disableRightHand;
    5.         public bool disableLeftHand;
    6.         TwoBoneIKConstraint rightArmConstraint;
    7.         TwoBoneIKConstraint leftArmConstraint;
    8.         private void OnAnimatorIK(int layerIndex)
    9.         {
    10.             if (!weaponLoadout.equippedWeapon) { return; }
    11.  
    12.             if (disableRightHand)
    13.             {
    14.                 animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
    15.                 animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
    16.             }
    17.             else
    18.             {
    19.                 animator.SetIKPositionWeight(AvatarIKGoal.RightHand, rightArmRig.weight * rightArmConstraint.weight);
    20.                 animator.SetIKRotationWeight(AvatarIKGoal.RightHand, rightArmRig.weight * rightArmConstraint.weight);
    21.                 animator.SetIKPosition(AvatarIKGoal.RightHand, weaponLoadout.equippedWeapon.rightHandGrip.position);
    22.                 animator.SetIKRotation(AvatarIKGoal.RightHand, weaponLoadout.equippedWeapon.rightHandGrip.rotation * Quaternion.Euler(-90, 0, 0));
    23.             }
    24.  
    25.             if (disableLeftHand)
    26.             {
    27.                 animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 0);
    28.                 animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 0);
    29.             }
    30.             else
    31.             {
    32.                 animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, leftArmRig.weight * leftArmConstraint.weight);
    33.                 animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, leftArmRig.weight * leftArmConstraint.weight);
    34.                 animator.SetIKPosition(AvatarIKGoal.LeftHand, weaponLoadout.equippedWeapon.leftHandGrip.position);
    35.                 animator.SetIKRotation(AvatarIKGoal.LeftHand, weaponLoadout.equippedWeapon.leftHandGrip.rotation * Quaternion.Euler(-90, 0, 0));
    36.             }
    37.         }