Making a camera look down in C#?

This is a simple question but, I have a main camera who has the original rotation on

X: 0
Y: 270
Z: 0

and I want to make the camera look down in code when something happens. So I made a float called xRotation and set it equal to 20. So, in code, I would like to make the x rotation = to xRotation, the y rotation = to 270, and the z rotation to still remain at 0. I tried using the code “Cam.transform.rotation = new Quaternion(xRotation, 270, 0, 0)” and it just makes the camera turn right and slightly down. Can someone tell me how i should properly do this? & if I need to use a quaternion, can someone explain the w float? Thanks!

If you look at the docs on Quaternions, you shouldn’t use Quaternion(x,y,z,w);. To use angles, write transform.rotation = Quaternion.Euler(20,90,0);. Also, 20 degrees is only slightly down. 90 should aim straight down.

Rotations are done in local y,z,x order, and the order usually matters, so sometimes you can’t do them all at once. Can do them in the exact order you want with something like:

transform.rotation = Quaternion.Euler(0,45,0); // starting: 45 down, around x
transform.Rotate(0,90,0); // add an extra 90 around y
transform.Rotate(0,0,5);  // add small twist on z

Most rotations are easier to do using a LookAt. To look down with head tilted right, say:
transform.rotation = Quaternion.LookRotation(Vector3.down, Vector3.right); That says to aim straight down, spun so that “up” is to your right.

There are two kinds of LookAts. transform.LookAt(...); aims you at a point in the game world. If you want to aim right, you have to pick a world position to the right of you, such as transform.position + Vector3.right. The other, Quaternion.LookRotation(...), takes a direction. in other words, it counts as always being at (0,0,0).