| forward | 要查看的方向。 |
| upwards | 定义向上方向的向量。 |
使用指定的 forward 和 upwards 方向创建旋转。
返回计算的四元数。
如果用于对变换进行定向,Z 轴将与 forward 对齐,
Y 轴与 upwards 对齐(如果这些向量是正交的)。
如果前进方向为零,则记录错误。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 relativePos = target.position - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); transform.rotation = rotation; } }
另请参阅:SetLookRotation。