Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Limiting hand rotation in lateupdate - How To?

Discussion in 'Animation' started by sstrong, Aug 24, 2021.

  1. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,271
    I set a hand IK target position and rotation in OnAnimatorIK using SetIKPosition and SetIKRotation (which works fine).

    I'd like to limit the left/right and up/down angles of the hand in LateUpdate using handTransform.localRotation.

    However, every rig seems to have some kind of different hand bone orientation. Has anyone been able to get this to work?

    BTW I'm NOT using Animation Rigging.
     
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,271
    I figure I need to do something like this, but cannot work out how to use the current hand bone localRotation (rather than the -1 to 1 muscle values).

    bone transform localRotation seems to use different sets of axis for different rigs.

    Code (CSharp):
    1.             angle = boneTrfm.localEulerAngles;
    2.  
    3.             angle.x *= sign.x;
    4.             angle.y *= sign.y;
    5.             angle.z *= sign.z;
    6.  
    7.             // Clamp angles here
    8.  
    9.             // Without clamping this should have no effect - but instead produces odd results
    10.             boneTrfm.localRotation =
    11.                 preQ
    12.                 * Quaternion.AngleAxis(new Vector3(0, angle.y, angle.z).magnitude, new Vector3(0, angle.y, angle.z).normalized)
    13.                 * Quaternion.AngleAxis(angle.x, new Vector3(1, 0, 0))
    14.                 * Quaternion.Inverse(postQ);
     
  3. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,271
    Here are some examples how rigs have different bone (hand) rotations which makes setting the localRotation difficult. I wonder if Unity have a way of determining this orientation that we can use at runtime.

    JodyRH.png BobRH.png RobotKyleRH.png BobLH.png JodyLH.png
     
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,558
  5. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,271
    Thanks for the suggestion. However, instead of just doing a simple transform.Rotate what I need is:
    1. What bone rotation / orientation is Unity expecting in the T-Pose position
    2. How to determine (at runtime if possible) the difference between the bone orientation Unity is expected and what the rig is actually set to.
     
    adamgolden likes this.