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

回到 Animator深入系列总目录

 

 

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

 

 

然后,和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, 1);
    }
}
View Code

 

posted @ 2016-01-03 18:03  HONT  阅读(4507)  评论(0编辑  收藏  举报