I’m working with IK for the first time, and can’t seem to get it to work.
In the Animator I have already checked “IK Pass”, and the avatar is configured correctly, but it just isn’t working.
This is the code I have:
using UnityEngine;
using System.Collections;
public class IKTest : MonoBehaviour {
public Animator anim;
public Transform leftfootAnchor;
public Transform rightfootAnchor;
void Start(){
anim=GetComponent<Animator>();
leftfootAnchor=GameObject.Find("LeftFootAnchor").transform;
rightfootAnchor=GameObject.Find("RightFootAnchor").transform;
anim.SetIKPositionWeight(AvatarIKGoal.LeftFoot,1);
anim.SetIKRotationWeight(AvatarIKGoal.LeftFoot,1);
anim.SetIKPositionWeight(AvatarIKGoal.RightFoot,1);
anim.SetIKRotationWeight(AvatarIKGoal.RightFoot,1);
}
// Update is called once per frame
void OnAnimatorIK(int layerIndex) {
anim.SetIKPosition(AvatarIKGoal.LeftFoot,leftfootAnchor.position);
anim.SetIKRotation(AvatarIKGoal.LeftFoot,leftfootAnchor.rotation);
anim.SetIKPosition(AvatarIKGoal.RightFoot,rightfootAnchor.position);
anim.SetIKRotation(AvatarIKGoal.RightFoot,rightfootAnchor.rotation);
}
}
I know there are better ways to do things, but I’m just playing around with IK at the moment. Does anyone see where I may have made an error? Or are there common “gotcha’s” that I may have missed?