Camera Placement in Platformer

Hal Brooks
3 min readOct 5, 2021

--

Object: Use Cinemachine to position main camera as player moves in game.

Camera progression as the player moves through the game.

In Unity select window > package manager then search for Cinemachine and install, see below.

Install Cinemachine from Package Manager.

Create an empty object called Camera_Progression to store ten virtual cameras (vcam) created from the cinemachine (CM) menu now available in Unity. For each vcam disable the CinemachineVirtualCamera, uncheck, and click on solo to show the virtual cameras view in the game window, see below. Do the same for the other nine CM_vcams, selecting views that cover the various platforms in the game. The main camera fill move to focus on a local area of the level as the player moves through the game.

CM_vcam1 solo toggle, left, is used to adjust the position and rotation for each camera trigger, right.

Now create an empty game objects named Camera_Triggers. Create another empty game object, naming it Camera_1_Trigger, as a child of Camera_Triggers, and add a box collider with is trigger checked. Edit the collider so the it is slightly above the platform, as shown above. Change the layer to Ignore Raycast. Create a C# script that triggers when the Player enters the collider the main camera switches to a position and rotation covering this box collider.

CameraTrigger script

Duplicate this nine times. Edit the colliders for Camera_1–10_Trigger to correspond to the view from the corresponding CM_vcam1–10.

Virtual cameras (grey & red CM icon), box colliders (green frames) for several camera triggers

The hierarchy window should look similar to that shown below.

Hierarchy for camera progression and camera triggers.

Finally attach the following LookAtPlayer script to the main camera to allow the camera to focus on the Player as they move through the game. To do this the Transform of the _player is grabbed in void Start(), and Camera.main.transform.LookAt is used to focus on the _player.

Look at Player script on Main Camera.

--

--

No responses yet