© 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 
(1)
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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.