Camera Look System in Unity
In this new project (3rd person shooter 3D game), the player has already the movement mechanic. Now it’s time to set up the camera system
Camera following the player’s movement
An easy approach is to place the Main Camera as a child of the Player gameobject
Camera rotation
For this, we will use the Player
script
What do we want to use for rotation?
We want to use the up-down and left-right mouse’s movement
What do we want to rotate and how?
We want to rotate the player’s rotation.y value (left-right)
And the camera’s rotation.x value (up-down)
For this, Unity has 2 axis called “Mouse X” and “Mouse Y”. Both are float values that can be found in Project Settings/Input Manager
They are the result of the mouse’s movement delta calculation
Mouse X will return the mouse’s X axis value (similar to Horizontal)
Mouse Y the Y axis value (similar to Vertical)
For rotation, there are several ways. We will use the last one
After getting a reference to the Main Camera Transform, this is the code: