步骤一
动画层级的设置里勾选IK Pass
1644731851(1).png
使用OnAnimatorIK
这个API会每帧调用,如同update
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoneRotationTest : MonoBehaviour
{
public GameObject girl;
private Animator anim;
public Transform LookAtTargetTrans;
void Start()
{
anim = girl.GetComponent<Animator>();
}
void OnAnimatorIK(int layerIndex)
{
//set bone local rotation
//anim.SetBoneLocalRotation(HumanBodyBones.Head, Quaternion.Euler(0, 60, 0));
////get bone local rotation
//Transform tran = anim.GetBoneTransform(HumanBodyBones.Head);
//Debug.Log(tran.rotation);
float angle_Z = Vector3.Angle(LookAtTargetTrans.position - transform.position, transform.forward);
Debug.Log(angle_Z);
anim.SetBoneLocalRotation(HumanBodyBones.Head, Quaternion.Euler(0, 0, angle_Z));
}
}
使用场景
- 人物在播放跑的动画的时候,同时将头转向到目标方向
- 物体在播放idle东皇状态时候,同时可以响应鼠标的方向来调整头部的转动










网友评论