【问题标题】:Game object not rotating to correct specified angle [duplicate]游戏对象没有旋转到正确的指定角度[重复]
【发布时间】:2017-11-26 04:35:09
【问题描述】:

我正在使用以下代码在给定时间段内旋转我的游戏对象:

    IEnumerator RotateMe(Vector3 byAngles, float inTime)
{
    Quaternion fromAngle = transform.rotation ;
    Quaternion toAngle = Quaternion.Euler(transform.eulerAngles + byAngles) ;
    for(float t = 0f ; t < 1f ; t += Time.deltaTime/inTime)
    {
        transform.rotation = Quaternion.Lerp(fromAngle, toAngle, t) ;
        yield return null ;
    }
}


public void runCoroutine(Vector3 destination)   {
    StartCoroutine(RotateMe(destination, 0.5f));
}

那我这样称呼它:

runCoroutine(new Vector3(0,0,-90));

我从测试中意识到我的游戏对象并没有旋转到指定的角度,而是关闭了它们。不太确定是什么原因造成的。

【问题讨论】:

  • 这是一个简短的回答:t &lt;= 1
  • @Draco18s 仍然有同样的问题。我尝试将时间从 0.5 减少到 0.1,结果更加不稳定。
  • 尝试在方法末尾添加transform.rotation = Quaternion.Lerp(fromAngle, toAngle, 1);

标签: unity3d unity5


【解决方案1】:

我会说使用 Lerp 方法更好。对于与时间相关的确切信息,您必须介绍 lerp 的比率。

transform.rotation = Quaternion.Lerp(fromAngle, toAngle, 1/value)

您可以控制“值”来控制旋转速度。我通常使用这种方法来获得更可控的旋转。

注意:确保 lerping 在“每帧”方法调用中完成;更新/固定更新/延迟更新

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多