什么是 Quaternion ,以及如何统一使用 Quaternion lerp?
what is Quaternion , and how to use a Quaternion lerp in unity?
我想在我尝试使用
时使对象在特定轴上旋转
void Rotate () {
transform.Rotate(0,0,0);
}
但它只是瞬间旋转,比我了解 四元数 一切都超出了我的头脑,我什么都不懂。
我只知道我知道有 Lerp 和 Slerp。
但我不知道如何使用它们,我想让对象从当前旋转旋转到特定轴
使用 Lerp。
请帮助我!!!
在此处提问之前先进行研究。谷歌搜索相同的问题会让你找到关于四元数的 Unity 官方文档 here.
下面是一个简单的例子,展示了如何使用局部变换和世界旋转 space。
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才能顺利旋转。在你的问题中,你只是在分配值,这就是你看不到它旋转的原因。
我想在我尝试使用
时使对象在特定轴上旋转void Rotate () {
transform.Rotate(0,0,0);
}
但它只是瞬间旋转,比我了解 四元数 一切都超出了我的头脑,我什么都不懂。 我只知道我知道有 Lerp 和 Slerp。 但我不知道如何使用它们,我想让对象从当前旋转旋转到特定轴 使用 Lerp。 请帮助我!!!
在此处提问之前先进行研究。谷歌搜索相同的问题会让你找到关于四元数的 Unity 官方文档 here.
下面是一个简单的例子,展示了如何使用局部变换和世界旋转 space。
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才能顺利旋转。在你的问题中,你只是在分配值,这就是你看不到它旋转的原因。