Quickie: Adding Mouse Sensitivity Options

Marcus Ansley
2 min readAug 13, 2021

--

This is just a quick article to cover how, with a couple of quick adjustments, we can control the camera look system’s sensitivity using a public variable (and even a slider in the Inspector) 😉

Back in our Player class, create a new private float called _mouseSensitivity and assign it a starting value of 1f. Mark this float as serializable using the ‘[SerializeField]’ attribute, and add in a ‘range’ attribute above it (or just to the left of the serialise attribute if you prefer). We can also add in a ‘[Header]’ attribute above this, and type in something like “Controller Settings” if we want things to look even tidier in the Inspector. This code should end up looking something like this:

If you were to head back into Unity and let it compile (assuming there are no compiling errors), you should see the Player class look a little different in the Inspector. Namely, it’ll have a slider that lets us set a _mouseSensitivity value between 0.1f and 3f. You’re welcome to change these values in the script if you’d like, but I’ve found this gives a fairly reasonable range for us to choose from.

Next, let’s start using this variable in our CameraLook method. Specifically, we’re going to want to multiply our mouseX and mouseY values respectively before they’re either added to or subtracted from the newPlayerRotation.y or newCameraRotation.x axis. This will increase, decrease, or maintain the effects of the player’s mouse x or y inputs depending on the float value decided on in the Inspector.

With that all set up, you should now be able to head back into Unity and give this a whirl! If we wanted to, we could fairly easily map a UI slider’s value in the game to this value, giving the player (rather than just the developer) control over the look sensitivity in game 😄

--

--

Marcus Ansley
Marcus Ansley

Written by Marcus Ansley

Game Developer | Game Design and Literature Graduate

No responses yet