回到 Animator深入系列总目录

要让代码控制IK,需要先在Animator中打开IK pass

Unity-Animator深入系列---控制IK-LMLPHP

Unity-Animator深入系列---控制IK-LMLPHP

然后,和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");
}

测试脚本:

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, );
}
}
04-14 12:26