| forward | 要查看的方向。 |
| upwards | 定义向上方向的向量。 |
使用指定的 forward 和 upwards 方向创建旋转。
Z 轴将与forward对齐,X 轴与 forward 和 upwards 之间的差积对齐,Y 轴与 Z 和 X 之间的差积对齐。\
如果 forward 或 upwards 量值为零,则返回恒等。
\如果 forward 和 upwards 共线,则返回恒等。
// You can also use transform.LookAt
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Transform target;
void Update() { Vector3 relativePos = target.position - transform.position;
// the second argument, upwards, defaults to Vector3.up Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up); transform.rotation = rotation; } }
另请参阅:SetLookRotation。