Unity LookAt和LookRotation的使用
始终看向某一个物体transform.LookAt(Obj.transform);Debug.DrawLine(transform.position, Obj.transform.position, Color.blue);保持和同一个物体,同一个朝向
transform.rotation = Quaternion.LookRotation(Obj.transform.forward); Debug.DrawRay(transform.position, Obj.transform.forward, Color.red);但是当Obj发生上下移动(不在同一个水平面)时,就能看到差别了,物体始终朝向Obj,但是物体只改变水平方向的转向
Vector3 dir = Obj.transform.position - transform.position; dir = new Vector3(dir.x, 0, dir.z); transform.rotation = Quaternion.LookRotation(dir); Debug.DrawRay(transform.position, dir, Color.green);
页:
[1]