Unity3D,仅在对象变换的旋转中更改音高



晚上好。我有一个GameObject,我需要改变它的俯仰(不影响它的偏航和滚动)。我有一个四元数,它存储旋转,我需要从中获得所需的pitch和设置到我的游戏对象。但是从四元数到欧拉角的强制转换操作并不是唯一的(一个四元数可以被表示为多个欧拉角三元组)。有可能做到这一点而不投射到欧拉角吗?

是的,可以通过操作四元数的原始组件(可怕)或使用unity的内置函数之一

Quaternion.AngleAxis() -可能你正在寻找的,你可以很容易地将旋转隔离为仅pitch。

但是在"静态方法"下面还有很多类似的函数头。

你可以像这样组合旋转(基于Unity的例子),在这种情况下,当前旋转与增量螺距旋转:

public class Example2 : MonoBehaviour
{
float rotateSpeed = 90;
// Applies a rotation of 90 degrees per second around the X axis for pitch
void Update()
{
float angle = rotateSpeed * Time.deltaTime;
transform.rotation *= Quaternion.AngleAxis(angle, Vector3.right);
}
}

最新更新