SOLVED - use the code below to make camera look down by 45 degrees.
Better code that doesn’t gimbal lock
Quaternion centeredRotation = Quaternion.Euler(camCenteredAngle, transform.eulerAngles.y, transform.eulerAngles.z);
//smoothly rotate the camera down towards the centered angle which means user wants to look at ground via c hotkey
transform.rotation = Quaternion.Slerp(transform.rotation, centeredRotation, Time.deltaTime * camSlerpToCenterSpeed);
//if you don't want to slerp just do this
// transform.rotation = centeredRotation;
The following code is prone to gimbal lock if you start to lerp/slerp.
```
**//get the camera’s current local euler angles
Vector3 camLocalEulerAngles = transform.localEulerAngles;
//setting x will make the camera look down at the ground at 45 degree angle
camLocalEulerAngles.x = 45;
//apply change to camera
transform.localEulerAngles = camLocalEulerAngles;**
```
Okay imagine you’re looking straight, now look down 45 degrees. No matter where you’re standing,you just tilt your head down by 45 degrees.
How do I do this in Unity?
I still haven’t got my head around the rotation math.
Here is my code. I want the camera to just look down at the terrain when the user presses the C key.
//when use hit's c key, the camera tilts down by 45 degrees to look at the terrain
if (Input.GetKey(KeyCode.C))
{
// Get a copy of your forward vector
Vector3 forward = transform.forward;
float headingAngle = Quaternion.LookRotation(forward).eulerAngles.y;
Quaternion testing = transform.rotation;
//this gets the camera to tilt down by 45 degrees
testing.x = 0.5f;
//if i don't set this to 0 the camera z ends up tilting, but if i zero it out the camera will always tilt in one direction
testing.z = 0f;
//.... ??
testing.y = 0f;
transform.rotation = new Quaternion(0.5f, 0, 0, 0);
//the mouse free look modifies this camRotationX value, i have to calculate this based upon the above code
//camRotationX += testing.x * Time.deltaTime;
//transform.rotation = testing;//Quaternion.Slerp(transform.rotation, transform.rotation + Vector3.down, 2.0f);
//no matter what this always just rotates the camera forward straight without any angle
//transform.eulerAngles = new Vector3(1, 0, 0);
}
Unity needs functions that are easier to use.
transform.rotatedownby(45);
transform.rotateupby(45);
transform.rotateupleftby(45);
transform.rotaterightby(45);

