【问题标题】:what is Quaternion , and how to use a Quaternion lerp in unity? [closed]什么是 Quaternion ,以及如何统一使用 Quaternion lerp? [关闭]
【发布时间】:2021-09-15 09:36:27
【问题描述】:

我想让一个对象在我尝试使用的特定轴上旋转

void Rotate () {
        transform.Rotate(0,0,0);
   }

但它只是立即旋转,而不是我了解 四元数,一切都超出了我的想象,我什么都不懂。 我只知道我知道有一个 LerpSlerp。 但我不知道如何使用它们,我想让对象从其当前旋转旋转到特定轴 Lerp。 请帮帮我!!!

【问题讨论】:

    标签: c# unity3d scripting


    【解决方案1】:

    在这里提问之前尝试进行研究。谷歌搜索同样的问题将带你到 Unity 的官方文档关于四元数here

    下面是一个简单的例子,展示了如何通过局部变换和世界空间旋转。

    void Update()
            {
                // Rotate the object around its local X axis at 1 degree per second
                transform.Rotate(Vector3.right * Time.deltaTime);
        
                // ...also rotate around the World's Y axis
                transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
            }
    

    下面展示如何使用四元数

     // Interpolates rotation between the rotations
        // of from and to.
        // (Choose from and to not to be the same as
        // the object you attach this script to)
    
        Transform from;
        Transform to;
        float speed = 0.1f;
        void Update()
        {
            transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed);
        }
    

    您还需要使用 Time.deltaTime 来平滑旋转它。在您的问题中,您只是在分配值,这就是为什么您看不到它在旋转。

    【讨论】:

    • 我已经搜索过了,但我什么都不懂,总是去统一文档搜索,但我什么都不懂
    • 也试试 youtube。有时它有助于视觉理解。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2016-10-22
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多