问题描述
我想使对象在我尝试使用的特定轴上旋转
void Rotate () {
transform.Rotate(0,0);
}
但它只是瞬间旋转,而不是我了解了四元数,一切都超出了我的头脑,我什么都不明白。 我只知道我知道有 Lerp 和 Slerp。 但我不知道如何使用它们,我想让对象从当前旋转到特定轴 带有 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 来平滑旋转。在您的问题中,您只是在分配值,这就是为什么您看不到它旋转的原因。