Quaternion.LookRotation 注视旋转

来源:互联网 发布:背叛了男朋友 知乎 编辑:程序博客网 时间:2024/05/22 16:40

Creates a rotation that looks along forward with the the head upwards along upwards

创建一个旋转,沿着forward(z轴)并且头部沿着upwards(y轴)的约束注视。也就是建立一个旋转,使z轴朝向view ?y轴朝向up。

Logs an error if the forward direction is zero.

如果forward方向是0,记录一个错误。

using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Transform target;void Update() {Vector3 relativePos = target.position - transform.position;Quaternion rotation = Quaternion.LookRotation(relativePos);transform.rotation = rotation;}}
0 0