| forward | 要朝向的方向。 |
| upwards | 定义向上方向的向量。 |
使用指定的 forward 和 upwards 方向创建旋转。
Z 轴将与 forward 对齐,X 轴与 forward 和 upwards 的叉积对齐,Y 轴与 Z 和 X 的叉积对齐。
如果 forward 的大小为零,则返回单位矩阵。
如果 forward 和 upwards 共线,或者 upwards 的大小为零,则结果与 Quaternion.FromToRotation 相同,其中 fromDirection 设置为正 Z 轴 (0, 0, 1),toDirection 设置为归一化的 forward 方向。
// 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。