Unity LookAt朝向目標位置


//朝向目標位置旋轉 (tan正切角=對邊/鄰邊*Mathf.Rad2Deg)
if (_target == null)
{
head.rotation = new Quaternion(0, 0, 0, 0);
}
Vector3 dis = _target.position - transform.position;
float angle = Mathf.Tan(dis.y / dis.x) * Mathf.Rad2Deg - 90;
//head.rotation = Quaternion.Euler(0, 0, angle);
head.eulerAngles = new Vector3(0, 0, angle);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM