Camera Look System in Unity

Joseph Hibbs
1 min readDec 12, 2023

--

Creating a camera rotation system can be a very hard process, so I hope this article will help you as a good starting point for one.

We first need to assign a float to mouseX and mouseY using the input variables found in player settings Input.

We then need to assign the player to rotate with the mouse X axis.

So, we create a local variable, equaling the player’s transform local eular angles. Setting the Y to plus and equal mouseX. Then reassign the new local variable to the transform rotation.

We basically do the same for camera but we need to get the main camera and assign it in start. We then create a local variable to store the camera’s local eular angles. Assign the X value of it to minus equal mouseY. We then need to have the local rotation since we have the camera as a child object of player to be assigned the local variable for the camera.

//x mouse
float mouseX = Input.GetAxis("Mouse X");
//y mouse
float mouseY = Input.GetAxis("Mouse Y");



//apply mouseX to player rotation y
Vector3 currentRotation = transform.localEulerAngles;
currentRotation.y += mouseX;
transform.rotation = Quaternion.AngleAxis(currentRotation.y, Vector3.up);

//apply mouseY to camera rotation X
Vector3 currentCameraRotation = _mainCamera.gameObject.transform.localEulerAngles;
currentCameraRotation.x -= mouseY;
_mainCamera.gameObject.transform.localRotation = Quaternion.AngleAxis(currentCameraRotation.x, Vector3.right);

--

--