- Home /
How to get a bones actual position when using IK
So I am using the built in IK system with a humanoid model. I have an idle animation playing, and override the hand to point to the player with:
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKPosition(AvatarIKGoal.RightHand, MyEnemy.transform.position);
Now that works fine until it comes time for me to figure out the position of the hand. I use RightHandBone.position to get the position of the bone, where RightHandBone is a public transform set in editor to the hand bone. The problem is this returns the position of the hand before the IK, as if it was still in the idle animation position.
The same thing happens if I create a new object and parent it to the hand and get the new objects position. Still returns the position of where the hand would be if it was not being effected by IK.
How can I get the real position of the hand?
"where RightHandBone is a public transform set in editor to the hand bone" ... how did you do this? How do you expose RightHandBone as a public transform in the editor? Thanks!
I believe I had a public transform variable on my script. I then found the bone in question and dragged it into the field in the inspector.
Answer by CiberX15 · Feb 19, 2017 at 10:52 PM
Derp. I figured it out. I was getting the bone position in the OnAnimatorIK() function, as such the bone position really hadn't been updated yet. Getting the bone position in the Update() function instead returned the bones correct location, after IK had been applied.