在我的Unity场景中,我试图通过头部运动来旋转立方体。这是我的代码:
m_cubeName.rotation = Quaternion.Lerp(m_cubeName.rotation, m_Camera.rotation, Time.deltaTime);
它似乎工作并旋转与头部完全相同的角度。我想使用乘法因子,这样当头部旋转时,比如1度,立方体旋转2度。
那么如何将qauternion旋转值转换为可以乘以因子的值?
答案 0 :(得分:3)
要将立方体旋转2倍,只需将其旋转两次:
Quaternion doubleCameraRotation = m_Camera.rotation * m_Camera.rotation;
m_cubeName.rotation = Quaternion.Lerp(
m_cubeName.rotation,
doubleCameraRotation,
Time.deltaTime);
要将旋转乘以非整数因子,您可以使用Quaternion.LerpUnclamped
,(或SlerpUnclamped
以获得更高的准确度),然后将缩放系数传递为t
。例如:
Quaternion doubleCameraRotation =
Quaternion.LerpUnclamped(Quaternion.identity, m_Camera.rotation, 2f);