Setting Main Camera Rotation

I can’t figure out how to set the rotation of the camera to an exact set of x,y,z values using C#. Once I realized that transform.position could set the position in a similar way to using the inspector, I figured it would be just as easy for the rotation. I need to set the camera for multiple positions for an rpg (map, third person, first person etc). I figured I save a flowing move of the camera for later. Any help would be greatly appreciated.

Don’t worry, it’s very simple:

  Camera.main.transform.rotation = Quaternion.Euler(x,y,z);

There’s some smooth move stuff on my blog - http://www.whydoidoit.com - smoothed quaternions, moving on a path - but that ain’t rocket science either :slight_smile:

currentRotation.x += Input.GetAxis(“Mouse X”) * sensitivity;
currentRotation.y -= Input.GetAxis(“Mouse Y”) * sensitivity;
currentRotation.x = Mathf.Repeat(currentRotation.x, 360);
currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle);
Camera.main.transform.rotation = Quaternion.Euler(currentRotation.y,currentRotation.x,0);
if (Input.GetMouseButtonDown(0))
Cursor.lockState = CursorLockMode.Locked;

That could be the answer:D

@whydoidoit This doesn’t work for me as when I try to set exact rotations for the camera it doesn’t do anything at all.