Camera Look System in Unity
Objective: Set up the Camera System
As you can see above, currently the camera is in a fixed position while the Player moves around the scene. The first thing we need to do is get the camera to follow the Player. There are many ways to do this such as Cinemachine but for now, we will use the easiest option and that is to make the camera a child object of the Player.
Now that the camera is following the Player, we need to first the viewing and angles of the camera relevant to the Player. For this project we want an over the shoulder style view. By using the settings in the image below we get the effect you see in the clip below the settings. For now this will do perfect and we can edit them further later if needed.
Now that the Player is moving and the camera is following, we want to be able to change where the Player is looking and be able to move in that direction. Currently the Player can move forward, back, left and right.
First, add a private Camera for the Main Camera in the Player script and assign the handle in the Start method and remember to null check.
Next, create a MovementView method. Create two float variables for the mouse axis inputs then, allow the player to turn left and right using a Vector3 for the Players Y-axis rotation using the mouse X-axis. We then use the Cameras X-axis rotation and the mouse Y-axis to allow the Player up and down viewing.
Finally we update the Movement method to use Local Space for the Velocity.