[SOLVED] Simple Way to Rotate an Object's Z Axis?

This seems like a simple question, but it’s really frustrating because it’s not done in any normal means (ie. transform.rotation.z).

My problem is when I try to rotate an object along the Z axis, it does not have the Z rotation that I set in the code.

Things I have tried and their outputs:

transform.rotation.z = 10;
  • Output: 168.696
transform.localRotation.z = 10;
  • Output: 168.696
transform.Rotate (Vector3 (0, 0, 10);
  • Output: 26.5

I know there is complex math Unity does when rotating an object, but how can I simply set a rotation to the number I specify?

NOTE: These results are with Z rotation starting at 0.

Any help would be greatly appreciated!

- Chris

I know why the first 2 are not working. You are attempting to set the ‘z’ of a quaternion.
Try instead :

transform.rotation = Quaternion.Euler(new Vector3(0,0,10));

The 3rd one, I would have thought, would work (except that you missed a bracket, but maybe that was a typo).

1 Like
transform.rotation = Quaternion.Euler(0, 0, 10);
1 Like

Yeah, I missed the 2nd closing parenthesis at the end when writing the code there. :sweat_smile:

You both posted at the same time with the same answer :wink:

That works! Thank you both for all the help (and the help in my previous question)!

np, you’re welcome.