角度慢速内旋转

Vector3 .RotateTowards

留下反馈

公共静态Vector3 RotateTowardsVector3 current, Vector3 target,float maxRadiansDelta,float maxMagnitudeDelta);

参量

当前正在管理的向量。
目标向量。
maxRadiansDelta两个向量之间的距离,以弧度为单位。
maxMagnitudeDelta弧度的长度。

退货

Vector3 RotateTowards生成的位置。

描述

current向旋转向量target

此功能与MoveTowards相似,不同之处在于将矢量视为方向而不是位置。尽管current矢量将准确落在目标上而不是过冲,但矢量将朝target方向旋转角度为maxRadiansDelta。如果大小currenttarget不同,那么结果的幅度将线性旋转过程中插入。如果将用作负值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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值