© Casey Hardman  2020
C. HardmanGame Programming with Unity and C#https://doi.org/10.1007/978-1-4842-5656-5_34

34. Mouse-Aimed Camera

Casey Hardman1 
West Palm Beach, FL, USA

Before we give the player any means of moving around, we’ll have to set up the player GameObject and provide them with a way of changing the direction they’re facing. We’ll do that here, implementing our first- and third-person cameras. Both systems will be handled by one script, and the player will be able to press a hotkey to smoothly switch from one to the other.

Coding the first-person camera will be a bit simpler. We position it where the player’s eyes would be, and we rotate it based on changes in the mouse position. Move the mouse left, the camera and the player will ...

Get Game Programming with Unity and C#: A Complete Beginner’s Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.