Camera Look System in Unity and Cursor Locking

Now that we have our player moving and the camera moving with the player, let’s take a look at how we can make a couple adjustments to that camera movement. To start, let’s get to work on creating a way to adjust the sensitivity of the mouse. First, we will quickly add a sensitivity value to our camera’s rotation method:

With this particular method, we are multiplying our movement values. This can allow us to also create a slider in the future for players to move about depending on their comfort zone to play with. Now what we will do is create some logic to hide and lock the players mouse cursor while in the game:

What this Locked code does is once the player starts the game, we will have the cursor locked and hidden on the screen. From here, we will need to create a method in which we can unlock the cursor so that if we what the player to be able to interact with menus, we have a visible cursor to make it easier on the player:

As Escape is usually the key game use to open up a menu to exit games, we will have it set up so that we will unlock our mouse to let the player move it around. With this in place, let’s take a look to see how it looks within our game: