简体   繁体   中英

How to increase rotation angle with Unity using Quaternion

In my Unity scene, I'm trying to rotate a cube wrt the head movement. 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.

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:

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 . For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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