Mouselook In Unity

Ben Pielstick
2 min readJun 14, 2021

Mouselook is one of the most common ways to control a character in a video game. Unfortunately, Unity doesn’t support this inherently, but as usual, it’s pretty easy to write a bit of code to make Unity do what you want.

Pretty easy

In this example, we’re running a script on the player game object, with an attached main camera for the player’s viewpoint. To look left and right we set the player’s rotation to the current Y rotation plus our mouse input, multiplied by our sensitivity scaler. Looking up and down is just as easy, by applying up and down rotation to our camera using the camera’s X rotation minus our mouse input which is again multiplied by a sensitivity scaler.

The only slightly tricky part here is that Unity rotation doesn’t map to mouse inputs directly, so we’re applying the mouse X axis to the transform Y rotation, and the mouse Y axis to the transform X rotation. Apart from that though, this is all it takes to get started with mouselook. Just don't forget to hide your cursor or it might be a little bit distracting.

--

--

Ben Pielstick

Game developer with over 12 years of experience, mainly focused on MMOs.