Search Unity

Is Animator.SetBoneLocalRotation working as intended for the hips?

Discussion in 'Animation' started by Laiken, Aug 25, 2020.

  1. Laiken

    Laiken

    Joined:
    Nov 18, 2015
    Posts:
    50
    'Animator.SetBoneLocalRotation' changes the local rotation of a bone to a given value, but not for the hips.
    Code (CSharp):
    1.      Animator anim;
    2.  
    3.      private void Start()
    4.      {
    5.          anim = GetComponent<Animator>();
    6.      }
    7.  
    8.      private void OnAnimatorIK(int layerIndex)
    9.      {
    10.          anim.SetBoneLocalRotation(HumanBodyBones.Hips, Quaternion.identity);
    11.      }
    I believe this was supposed to lock the hips local rotation on 0/0/0 correct? It's affecting the hips rotation somehow but not as expected. Can anyone confirm this if this is a bug? Maybe I'm missing something?

    I'm trying to lock the hips at a certain rotation. It's easy to do it on LateUpdate but I need to do it in OnAnimatorIK because I am using some IKs.
     
  2. hogdotmac

    hogdotmac

    Joined:
    Nov 21, 2016
    Posts:
    2
    I also get this bug, if i do:
    Code (CSharp):
    1. var t = animator.GetBoneTransform(HumanBodyBones.Hips);
    2. animator.SetBoneLocalRotation(HumanBodyBones.Hips, t.localRotation);
    3.  
    the hips don't stay where they are supposed to be, but are rotated twice by that rotation. I read somewhere this bug is not getting fixed because it would break backwards compatibility?
    https://issuetracker.unity3d.com/is...t-setbonelocalrotation-is-set-on-onanimatorik
    is there some way to disable this behavior or do we have to hard code a work around for the hips?
    like so?:
    Code (CSharp):
    1. animator.SetBoneLocalRotation(HumanBodyBones.Hips, Quaternion.Inverse(t.localRotation) * ...);
    which seems really dirty

    p.s: the rotation is still off and this does not work, it's still off by 7°

    how can we get the hips to rotate to an exact rotation?
     
    Last edited: Jan 27, 2022
  3. hogdotmac

    hogdotmac

    Joined:
    Nov 21, 2016
    Posts:
    2
    seems it has to be done via bodyRotation

    Code (CSharp):
    1. var t = animator.GetBoneTransform(HumanBodyBones.Hips);
    2. animator.bodyRotation *= Quaternion.Inverse(t.localRotation) * ...;