Search Unity

Wrong rotation when calling SetBoneLocalRotation() with current bone rotation

Discussion in 'Animation' started by tigger, Sep 23, 2019.

  1. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    I would expect the rotation of a bone to be unchanged by the following (performed within OnAnimatorIK() ).
    Basically, I'm getting the bone's currentRotation from the animator and using SetBoneLocalRotation() to set that currentRotation back into the bone.

    var currentBoneRotation = animator.GetBoneTransform(boneID).rotation;
    animator.SetBoneLocalRotation(boneID, currentBoneRotation);

    However, when I do this, the bone's orientation *on screen* is changed dramatically. It's nowhere close to where it should be.

    For example, if the current quat eulers for UpperArm are (13.2, 15.4, 172.2), calling SetBoneLocalRotation() using that quat and then calling animator.GetBoneTransform.rotation returns (13.4, 15.5, 172.2) (reasonably close to the original). However, in the viewport, the actual orientation of the upperArm in completely different.

    Strangely enough, if I do the same test for LeftShoulder, everything looks fine.

    Running v2018.3.2f1 Personal

    Update: I'm wondering if my problem has to do with this https://forum.unity.com/threads/req...n-optimised-mechanim-animated-charact.449145/
    animator.GetBoneTransform.rotation isn't returning a local rotation; it's returning the rotation wrt the *root* object, not the parent object.
     
    Last edited: Sep 23, 2019
  2. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    My mistake.

    The code setting currentBoneRotation above uses Transform property "rotation" rather than "localRotation".
    Using "localRotation" fixes the problem.
     
    CptKen likes this.