# Question Limiting hand rotation in lateupdate - How To?

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

1. ### 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

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

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.

Joined:
Jun 17, 2019
Posts:
1,558
5. ### 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.