【问题标题】:Unity - Wheels rotation [duplicate]Unity - 车轮旋转[重复]
【发布时间】:2021-07-18 14:41:49
【问题描述】:

我有一个关于旋转轮子的问题,代码工作正常,但我需要它是平滑的,我不知道该怎么做,在代码中添加什么。欢迎任何形式的帮助

//Rotation - WHEELS
CurrentRotation = Horizontal * RotationSpeed * Time.deltaTime;
Wheels[4].transform.localRotation = Quaternion.Euler(Wheels[4].transform.localRotation.x, Mathf.Clamp(CurrentRotation, -MaximumRotation, MaximumRotation), Wheels[4].transform.localRotation.z);
Wheels[5].transform.localRotation = Quaternion.Euler(Wheels[5].transform.localRotation.x, Mathf.Clamp(CurrentRotation, -MaximumRotation, MaximumRotation), Wheels[5].transform.localRotation.z);

     

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    我会尝试使用Quaternion.Slerp。由于我目前在移动设备上,因此我无法输入很长的解释。文档应该解释得很好。

     public float speed;
     
     void Update(){
         transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, speed*Time.deltaTime);
     }
    

    它应该随着时间的推移平滑地旋转你的对象到新的旋转。

    【讨论】:

    • 你救了我一整天,非常感谢
    • 很高兴我能帮上忙!如果它解决了您的问题,您可以通过单击答案左侧的箭头来关闭问题。它让有类似问题的其他人知道这是修复它的解决方案。
    猜你喜欢
    • 2018-10-24
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多