Making the camera follow the player

2D Game Design with Unity

🕑 This lesson will take about 17 minutes

In this lesson, you will learn how to write code that will make the camera follow the player in a 2D game built in Unity. Firstly, we will look at how to add basic camera movement (where the camera tracks the exact position of the player). In the second part of the lesson video, we will look at how to make camera movement smoother and allow the player to see further ahead when walking or running in a platformer game.

The code to implement the camera movement will be added to a script called ‘CameraController.cs’ (scroll down for the sample code).

Game art, tiles and sprites from the Free Pixel Space Platform pack are used in this lesson video and can be downloaded from the Unity Asset Store.

Is YouTube blocked at school? Watch on Google Drive.

Sample code

Next lesson: Respawning the player