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

27. Camera Movement

Casey Hardman1 
(1)
West Palm Beach, FL, USA
 

First things first, let’s get some camera movement in working order. The player has to be able to move around the stage to be able to see the whole thing, after all. We’ll allow the player to move the camera with the arrow keys as well as by right-clicking and dragging with the mouse. We’ll also provide the option to use the scroll wheel to zoom in or out, which lets the player control how close their camera is to the stage.

All of the movement will be applied to a Vector3 variable called targetPosition. Instead of directly applying the movement to the camera Transform, we update ...

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.