這幾天一直被一個問題困擾着。因為要做一個射擊的小demo,涉及到地面上的人射擊空中的飛機。
但是動畫中的人物的頭部要看向飛機才會更真實,可是我人物里的頭用Transform根本找不到啊!!!
苦惱了好久,今天想着去Animator里找找有木有可用的函數,媽蛋 一找就有收獲!!!
原先是醬紫。頭部是正常的角度。
加上以下代碼便會有改變~~Surprise~~~!!!
private void OnAnimatorIK(int layerIndex)
{
float angle_Z = Vector3.Angle(player.position - transform.position, transform.forward);
Debug.Log(angle_Z);
animator.SetBoneLocalRotation(HumanBodyBones.Head, Quaternion.Euler(0, 0, angle_Z));
}
現在運行!!!