- Home /
Problem with rotations and IK
Hello,
I ran into a problem this week with IK regarding rotations. I was able to reproduce the problem (or is it just me not understanding how IK works ?) using the following script:
 public class HumanoIKControl : MonoBehaviour {
 
     Animator avatar = null;
 
     // Use this for initialization
     void Start () {
         avatar = GetComponent<Animator>();
 
     }
 
     void OnGUI()
     {
         if (GUILayout.Button("FakeIK"))
         {
             avatar.SetBool("FakeIK", true);
         }
     }
 
     void Update()
     {
         if (avatar.GetBool("FakeIK"))
         {
             Debug.Log(" Update " + avatar.GetBoneTransform(HumanBodyBones.LeftHand).rotation.eulerAngles.x);
         }
     }
 
     void OnAnimatorMove()
     {
         if (avatar.GetBool("FakeIK"))
         {
             Debug.Log("AnimatorMove " + avatar.GetBoneTransform(HumanBodyBones.LeftHand).rotation.eulerAngles.x);
         }
     }
 
     void OnAnimatorIK()
     {
 
      
          if(avatar.GetBool("FakeIK"))
         {
             avatar.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
             avatar.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
 
              Debug.Log("IK " + avatar.GetBoneTransform(HumanBodyBones.LeftHand).rotation.eulerAngles.x);
             
             avatar.SetIKPosition(AvatarIKGoal.LeftHand, avatar.GetBoneTransform(HumanBodyBones.LeftHand).position);
             avatar.SetIKRotation(AvatarIKGoal.LeftHand, avatar.GetBoneTransform(HumanBodyBones.LeftHand).rotation);
         }
       
         else
         {
             avatar.SetIKPositionWeight(AvatarIKGoal.LeftHand, 0);
             avatar.SetIKRotationWeight(AvatarIKGoal.LeftHand, 0);
 
         }
     }
 
 }
I attached this script to the U_Character_REF avatar from the tutorial to be sure the problem was not coming from my own avatar (which presents the same strange behaviour)
When I activate FakeIK through the GUI button, the left hand position remains the same but its rotation changes on time and then stays fixed.
I thought my code was supposed to not move the hand since I ask the IK to put it at the exact same position and rotation as it is, or maybe am I missing or misunderstanding something ? Of course, the same goes with the other hand and the feet
Here is the output I get in the console regarding the X euler angle
It first shows this :
Update 308.2965
AnimatorMove 308.2965
IK 308.2965 
and then loops showing this :
Update 358.4016
AnimatorMove 358.4016
IK 308.2965 
I don't understand why the value changes after the first IK pass and why it is different only in the IK pass afterwards
Thanks !
Ok, for my last question, the value of I$$anonymous$$ is the value before I$$anonymous$$ occurs, that explains the difference on this part. But I still don't get why there is this offset between the rotation I ask for and the rotation I$$anonymous$$ gives
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                