微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

什么是四元数,以及如何统一使用四元数 lerp?

如何解决什么是四元数,以及如何统一使用四元数 lerp?

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

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

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

解决方法

在问这里之前先尝试研究一下。谷歌搜索同样的问题会让你找到关于 Quaternion here 的 Unity 官方文档。

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

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 来平滑旋转。在您的问题中,您只是在分配值,这就是为什么您看不到它旋转的原因。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。