unity3d 四元数外观旋转
示例
Quaternion.LookRotation(Vector3forward[,Vector3up])将创建一个四元数旋转,该旋转向前看“向下”向前的向量,并使Y轴与“向上”向量对齐。如果未指定up向量,Vector3.up则将使用。
旋转此游戏对象以查看目标游戏对象
//在名为Target的场景中找到一个游戏对象
public Transform target = GameObject.Find("Target").GetComponent<Transform>();
//我们从目标位置减去我们的位置以创建一个
//从我们的位置指向目标位置的向量
//如果我们颠倒顺序,我们的旋转将偏离180度。
Vector3 lookVector =target.position- transform.position;
Quaternion rotation = Quaternion.LookRotation(lookVector);
transform.rotation = rotation;