Transform.LookAt 注视

function LookAt (target : Transform, worldUp : Vector3 = Vector3.up) : void

Description描述

Rotates the transform so the forward vector points at /target/'s current position.

旋转物体,这样向前向量指向target的当前位置。简单说,

旋转物体使z轴指向目标物体。

Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis. worldUp is only a hint vector. The up vector of the rotation will only match the worldUp vector if the forward direction is perpendicular to worldUp

在由worldUp向量示意的方向的y轴旋转物体,如果你忽略worldUp参数,这个函数将使用世界的y轴。worldUp只是一个示意向量,如果向前方向是与worldUp垂直的,旋转的向上向量将仅匹配worldUp向量。

翻译的感觉很别扭,下面是我的经验总结:

当该物体设置了LookAt并指定了目标物体时,该物体的z轴将始终指向目标物体,在设置了worldUp轴向时,该物体在更接近指定的轴向是旋转便的灵活,注意worldUp指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform target;
	void Update() {
		transform.LookAt(target);
	}
}
// This complete script can be attached to a camera to make it
// continuously point at another object.
//这个完成的脚本附加到一个摄像机,使它连续指向另一个物体。
// The target variable shows up as a property in the inspector.
// Drag another object onto it to make the camera look at it.
//target变量作为一个属性显示在检视面板上
//拖动另一个物体到这个上面,是摄像机注视它
var target : Transform;

// Rotate the camera every frame so it keeps looking at the target
//每帧旋转摄像机,这样它保持注视目标
function Update() {
	transform.LookAt(target);
}

• function LookAt (worldPosition : Vector3, worldUp : Vector3 = Vector3.up) : void

Description描述

Rotates the transform so the forward vector points at worldPosition.

旋转变换,这样向前向量指向worldPosition。简单说,

旋转物体使z轴指向worldPosition

Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis. worldUp is only a hint vector. The up vector of the rotation will only match the worldUp vector if the forward direction is perpendicular to worldUp

在由worldUp向量示意的方向的y轴旋转物体,如果你忽略worldUp参数,这个函数将使用世界的y轴。worldUp只是一个示意向量,如果向前方向是与worldUp垂直的,旋转的向上向量将仅匹配worldUp向量。

翻译的感觉很别扭,下面是我的经验总结:

当该物体设置了LookAt并指定了目标物体时,该物体的z轴将始终指向目标物体,在设置了worldUp轴向时,该物体在更接近指定的轴向是旋转便的灵活,注意worldUp指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		transform.LookAt(Vector3.zero);
	}
}
// Point the object at the world origin
//使物体注视世界坐标原点
transform.LookAt(Vector3.zero);
最后修改:2010年12月19日 Sunday 18:41

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。