ksumarine
ksumarine

Reputation: 782

Continuous Quaternion Rotation

I'm new to Unity, so please bear with me. I'm trying to continuously rotate a GameObject (sphere) using Quaternions, but I haven't been able to figure it out from examples.

I was successful using...

transform.Rotate(new Vector3(0, 0, 1), 50f * Time.deltaTime);

but I would like to replicate how a sphere would actually rotate in 3d space, not just along 1 axis.

From the examples I've found, the rotation stops once it reaches the "end".

Sorry if this is a basic/noob question. Any help is greatly appreciated!

Upvotes: 0

Views: 1886

Answers (1)

kolenda
kolenda

Reputation: 2811

If you want the constant rotation, like an asteroid but around some custom axis then just pass this axis instead of your Vector3(0, 0, 1).

This vector can be anything, like (1,2,3), but I don't remember if it has to be normalized or not.

EDIT:

If you need more control then you may create few quaternions and concatenate them:

Quaternion q1 = Quaternion.AngleAxis(10f * Time.deltaTime, Vector3.right);
Quaternion q2 = Quaternion.AngleAxis(20f * Time.deltaTime, Vector3.forward);    
Quaternion q3 = Quaternion.AngleAxis(30f * Time.deltaTime, Vector3.up);
Quaternion q = q1 * q2 * q3;

You just need to be aware that q will depend on the order of multiplication, because for quaternions q1 * q2 is not the same as q2 * q1.

Upvotes: 1

Related Questions