Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Transform.LookAt 注视
# [Transform](Transform.html).LookAt 注视 function *LookAt* (*target* : [Transform](Transform.html), *worldUp* : [Vector3](../Vector3/Vector3.html) = [Vector3.up](../Vector3/Vector3.up.html)) : 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 指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。 * [C#](#) * [JavaScript](#) ``` 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](../Vector3/Vector3.html), *worldUp* : [Vector3](../Vector3/Vector3.html) = [Vector3.up](../Vector3/Vector3.up.html)) : 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 指的是世界空间,不论你物体在什么位置,只要接近指定的轴方向,旋转会变的更灵活。 * [C#](#) * [JavaScript](#) ``` 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); ```
da
2022年5月23日 14:50
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码