简体   繁体   English

如何使用四元数使用Unity增加旋转角度

[英]How to increase rotation angle with Unity using Quaternion

In my Unity scene, I'm trying to rotate a cube wrt the head movement. 在我的Unity场景中,我试图旋转带有头部运动的立方体。 Here's my code: 这是我的代码:

m_cubeName.rotation = Quaternion.Lerp(m_cubeName.rotation, m_Camera.rotation, Time.deltaTime);

It seems to work and rotates exactly the same angle as the head. 它似乎可以工作并且旋转与头部完全相同的角度。 I want to use a multiplying factor so that when the head rotates, say 1 degree, the cube rotates 2 degrees. 我想使用一个乘数,以便当头部旋转(例如1度)时,立方体旋转2度。

So how do I convert the qauternion rotation value to something I can multiply with a factor? 那么,如何将四元数旋转值转换为可以乘以因子的乘积呢?

To rotate the cube by a factor of 2, just rotate it twice: 要将多维数据集旋转2倍,只需将其旋转两次:

Quaternion doubleCameraRotation = m_Camera.rotation * m_Camera.rotation;

m_cubeName.rotation = Quaternion.Lerp(
    m_cubeName.rotation,
    doubleCameraRotation,
    Time.deltaTime);

To multiply the rotation by a non-integer factor, you can use Quaternion.LerpUnclamped , (or SlerpUnclamped for better accuracy) then pass the scaling factor as t . 要将旋转乘以非整数因子,可以使用Quaternion.LerpUnclamped (或SlerpUnclamped以提高精度),然后将缩放因子传递为t For example: 例如:

Quaternion doubleCameraRotation = 
    Quaternion.LerpUnclamped(Quaternion.identity, m_Camera.rotation, 2f);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM