- Home /
How to Aim Animator.SetIKRotation() to direction WRT hand bone rotation offset
I'm trying to make a firearm which is parented to the hand aim directly forward to where the character is facing.
I assumed this would be easy with
Animator.SetIKRotation(AvatarIKGoal.RightHand, Quaternion.LookRotation(SubjectObj.transform.forward));
But I'm testing this on 4 different rigs and getting inconsistent results because of the default orientation of hand bones - also screwing it up is the axis of the hand bones.
Currently the weapon is put into the hand like this:
Quaternion WeaponOrientationInHand()
{
Quaternion foo = Quaternion.LookRotation(
(Subject.InvertHandForward ? -RightHandBone().right : RightHandBone().right),
RightHandBone().TransformDirection(Subject.Stats.ThumbDirection));
return foo;
}
bonetransform.right is X aiming down the arm. Some rigs have it inverted.. This part actually works great. The weapon sets in the hand perfectly every time even with totally jacked up bone setups.
Then the weapon it parented to the hand bone and I make IK calls to put the hand bone where I want it, but then I need to rotate the hand so that the gun actually points forward but I can't seem to figure out the rotation math to do it. I'm stuck here.
I've tried various things to get the rotation but bottom line I can't figure out how to compensate for the base hand rotation offset variance even when I know all of the correct variables. ThumbDirection and X direction should be enough to formulate a signed direction but I need some help figuring out doing this with the rotations respecting that.
More info in this thread with pics, progress, etc.. http://forum.unity3d.com/threads/how-to-aim-animator-setikrotation-to-direction-wrt-hand-bone-rotation-offset.355941/
Your answer
Follow this Question
Related Questions
How do you manually override mecanim's interpolation with rotations? 2 Answers
Mecanim IK Foot Rotation 2 Answers
Animate arm to grab object with IK/Mecanim 0 Answers
Problem with rotations and IK 0 Answers
IK for hands 0 Answers