用户工具

站点工具


侧边栏

script:unityengine:classes:transform:transform.lookat

Transform.LookAt 看向

JavaScript ⇒ LookAt(target: Transform, worldUp: Vector3 = Vector3.up): void;
C# ⇒ void LookAt(Transform target, Vector3 worldUp = Vector3.up);

Parameters 参数

targetObject to point towards.
要指向的对象
worldUpVector specifying the upward direction.
向量指定的向上的方向。

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指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。

JavaScript:

	// 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.
	var target : Transform; 
 
	// Rotate the camera every frame so it keeps looking at the target 
	function Update() {
		transform.LookAt(target);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Transform target;
    void Update() {
        transform.LookAt(target);
    }
}

JavaScript ⇒ LookAt(worldPosition: Vector3, worldUp: Vector3 = Vector3.up): void;
C# ⇒ void LookAt(Vector3 worldPosition, Vector3 worldUp = Vector3.up);

Parameters 参数

worldPositionPoint to look at.
要看向的点
worldUpVector specifying the upward direction.
向量指定的向上的方向。

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指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。

JavaScript:

	// Point the object at the world origin
	transform.LookAt(Vector3.zero);

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Example() {
        transform.LookAt(Vector3.zero);
    }
}

Transform

script/unityengine/classes/transform/transform.lookat.txt · 最后更改: 2016/08/02 05:37 (外部编辑)