【发布时间】:2021-09-15 09:36:27
【问题描述】:
我想让一个对象在我尝试使用的特定轴上旋转
void Rotate () {
transform.Rotate(0,0,0);
}
但它只是立即旋转,而不是我了解 四元数,一切都超出了我的想象,我什么都不懂。 我只知道我知道有一个 Lerp 和 Slerp。 但我不知道如何使用它们,我想让对象从其当前旋转旋转到特定轴 Lerp。 请帮帮我!!!
【问题讨论】:
我想让一个对象在我尝试使用的特定轴上旋转
void Rotate () {
transform.Rotate(0,0,0);
}
但它只是立即旋转,而不是我了解 四元数,一切都超出了我的想象,我什么都不懂。 我只知道我知道有一个 Lerp 和 Slerp。 但我不知道如何使用它们,我想让对象从其当前旋转旋转到特定轴 Lerp。 请帮帮我!!!
【问题讨论】:
在这里提问之前尝试进行研究。谷歌搜索同样的问题将带你到 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 来平滑旋转它。在您的问题中,您只是在分配值,这就是为什么您看不到它在旋转。
【讨论】: