0

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!

10
  • I think you could log Debug.Log("Current rotation: " + transform.rotation) while using the above Rotate function. This should spit out the Quaternion of the rotation in the console. Commented Aug 2, 2018 at 19:18
  • Thank you, this does write out the Quaternion, but it doesn't solve the question :/ Commented Aug 2, 2018 at 20:10
  • Clarify what the "end" is. Commented Aug 3, 2018 at 9:28
  • @meowgoesthedog I think the "end" was because I was using Quaternion.Lerp? It would rotate how I wanted, but stop once it reached a point. I'd like it to keep freely rotating as if it were a asteroid, basically. Commented Aug 3, 2018 at 14:17
  • But what does transform.Rotate have to do with Quaternion.Lerp? You are not lerping anything here. Commented Aug 3, 2018 at 14:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd like to rotate around multiple axes, which is why I'd like to use Quaternions (If I'm understanding them correctly). I do want to rotate like a freely rotating asteroid, basically

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.