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);

posted @ 2019-08-27 17:01  傅睿鹏  阅读(4294)  评论(0)    收藏  举报