Limiting hand rotation in lateupdate - How To?

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.

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.

            angle = boneTrfm.localEulerAngles;

            angle.x *= sign.x;
            angle.y *= sign.y;
            angle.z *= sign.z;

            // Clamp angles here

            // Without clamping this should have no effect - but instead produces odd results
            boneTrfm.localRotation =
                preQ
                * Quaternion.AngleAxis(new Vector3(0, angle.y, angle.z).magnitude, new Vector3(0, angle.y, angle.z).normalized)
                * Quaternion.AngleAxis(angle.x, new Vector3(1, 0, 0))
                * Quaternion.Inverse(postQ);

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.

Yeah… I don’t think I’ve ever seen 2 different models have consistent rotation on joints. There’s a free asset you could check out for IK and rotation stuff which has “rotation offsets” which worked great for me, maybe you find a solution somewhere in this: Inverse Kinematics | Animation Tools | Unity Asset Store

Thanks for the suggestion. However, instead of just doing a simple transform.Rotate what I need is:

  • What bone rotation / orientation is Unity expecting in the T-Pose position
  • How to determine (at runtime if possible) the difference between the bone orientation Unity is expected and what the rig is actually set to.
1 Like