Vector3 .RotateTowards
公共静态Vector3 RotateTowards(Vector3 current, Vector3 target,float maxRadiansDelta,float maxMagnitudeDelta);
参量
| 当前 | 正在管理的向量。 |
| 目标 | 向量。 |
| maxRadiansDelta | 两个向量之间的距离,以弧度为单位。 |
| maxMagnitudeDelta | 弧度的长度。 |
退货
Vector3 RotateTowards生成的位置。
描述
current向旋转向量target。
此功能与MoveTowards相似,不同之处在于将矢量视为方向而不是位置。尽管current矢量将准确落在目标上而不是过冲,但矢量将朝target方向旋转角度为maxRadiansDelta。如果大小current和target不同,那么结果的幅度将线性旋转过程中插入。如果将用作负值maxRadiansDelta,则矢量将旋转远离, target/ 直到其指向完全相反的方向,然后停止。
<span style="color:#455463"><span style="color:#455463">使用UnityEngine;
使用System.Collections;
公共类ExampleClass:<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.html" href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.html">MonoBehaviour</a>
{
//目标标记。
<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Transform.html" href="https://docs.unity3d.com/ScriptReference/Transform.html">转换</a>目标;
//弧度/秒的角速度。
浮动速度
无效<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Experimental.PlayerLoop.Update.html" href="https://docs.unity3d.com/ScriptReference/Experimental.PlayerLoop.Update.html">更新</a>()
{
<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Vector3.html" href="https://docs.unity3d.com/ScriptReference/Vector3.html">Vector3</a> targetDir = target.position-transform.position;
//步长等于速度乘以帧时间。
浮步=速度* <a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Time-deltaTime.html" href="https://docs.unity3d.com/ScriptReference/Time-deltaTime.html">Time.deltaTime</a> ;
<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Vector3.html" href="https://docs.unity3d.com/ScriptReference/Vector3.html">Vector3</a> newDir = <a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html" href="https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html">Vector3.RotateTowards</a>(transform.forward,targetDir,step,0.0f);
<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html" href="https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html">Debug.DrawRay</a>(transform.position,newDir,<a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Color-red.html" href="https://docs.unity3d.com/ScriptReference/Color-red.html">Color.red</a>);
//将我们的位置移近目标。
transform.rotation = <a data-cke-saved-href="https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html" href="https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html">四元数</a> .LookRotation(newDir);
}
}</span></span>
3002

被折叠的 条评论
为什么被折叠?



