Hello everyone,
I have been playing around with Unity for a while now. I’ve been checking out existing project for inspiration on how to do thing. Now I would like to re-implement some of the things I saw, just to make sure I understand all that
1.) When I apply Transform.Rotate() it seems to rotate around whatever Axis I want it to relative to the previous rotation’s value.
The code sample in the docs is as follows:
transform.Rotate(Vector3.right * Time.deltaTime);
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
If I wanted to express that same thing with Quaternions, how would you do it?
The second rotation seems simple:
transform.rotation = Quaternion.Lerp ( transform.rotation, Quaternion.Euler(Vector3.up), Time.deltaTime);
But how do you apply the first rotation around the local Vector3.right axis with Quaternions?
Would the
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(Vector3.right), Time.deltaTime);
transform.rotation = Quaternion.Lerp ( transform.rotation, Quaternion.Euler(Vector3.up), Time.deltaTime);
be equal to the rotation from the first code snippet?
2.) Nice thing about Quaternion.Lerp is that I can let the object to rotate the object by absolute values over time or approximate it. If I did not use Quaternions but I used Rotate() method, how could I maximize the rotation of the object? eg: I want to rotate that object by 30 degrees around the world’s Y axis in 3 seconds in equal steps: 10degrees/second and then apply a 30degree rotation around to local X axis, again with 10 degrees/second.
Is it easier to do with Quaternions?
3.) Combining Quaternions is confusing the hell out of me.
Example:
Quaternion rotR = Quaternion.Euler(Vector.right * Time.deltaTime);
Vector3 localUp = transform.InverseTransformDirection(Vector3.up);
Quaternion rotU = Quaternion.Euler(localUp * Time.deltaTime);
transform.rotation = rotR*rotU;
// is the above equal with the following if I replace the transform.rotation line with this:
transform.rotation = rotR;
transform.rotation = rotU;