回到 Animator深刻系列總目錄html
要讓代碼控制IK,須要先在Animator中打開IK passide
而後,和IK相關的代碼須要放到相應的函數中去:函數
void OnAnimatorIK() { Debug.Log("OnAnimatorIK"); }
而若是是StateMachineBehaviour,IK操控的代碼是在:測試
public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateIK(animator, stateInfo, layerIndex); Debug.Log("OnStateIK"); }
測試腳本:spa
using UnityEngine; using System.Collections; public class IKTest : MonoBehaviour { public Animator animator; public Transform ikTarget; void OnAnimatorIK() { animator.SetIKPosition(AvatarIKGoal.LeftFoot, ikTarget.position); animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, 1); } }