动画IK控制

public class L45 : MonoBehaviour
{
    public Animator ani;
    public Transform trans;
    // Start is called before the first frame update
    void Start()
    {
        ani = GetComponent<Animator>(); 
       
    }
    private void OnAnimatorIK(int layerIndex)
    {
        //如何进行IK控制
        //1.在状态机的层级设置中开启IK通道
        //2.通过IK回调函数来控制IK
        //Animator中IK相关的API
        //头部相关API
        //(全局权重,身体权重,头部权重,眼睛权重,运动受限(0:角色不受限制,1:角色完全固定无法执行该lookat))
        ani.SetLookAtWeight(1,0.5f,0.5f);//头部IK权重
        ani.SetLookAtPosition(trans.position);//头部IK看向的位置

        //四肢相关API
        //(想要设置权重的四肢枚举,权重)
        ani.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);//设置IK位置权重
        ani.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);//设置IK旋转权重

        ani.SetIKPosition(AvatarIKGoal.RightHand, trans.position);//设置IK对应位置
        ani.SetIKRotation(AvatarIKGoal.RightHand, trans.rotation);//设置IK对应角度

    }
}
posted @ 2025-04-09 11:20  cannedmint  阅读(16)  评论(0)    收藏  举报