Cinemachine

Installation

  1. Go to Window > Package Manager.

  2. Under the Packages dropdown select Unity Registry

  3. In the search bar type cinemachine

  4. Select the Cinemachine package and click Install

Following a 2D Character

Tutorial

  1. In your scene inside the hierarchy right click and select Cinemachine > 2D Camera

  2. Select the camera. In the inspector, drag your player game object into the Follow argument.

  3. Next make adjustments to the camera. It may be helpful to see both the scene view and the game view. You can adjust things like:

    • Increase orthographic size for how much the camera sees

    • Set a larger dead zone width so that the camera only starts moving when the character is further away from the desired position of the camera on the player.

    • Grab the camera in the game view so that the player is off center in the frame.

    • Set the soft zone so there is a little leeway when the camera re orients to focus on the player as it moves.

    • Add a Cinemachine Confiner 2D extension (at the bottom of cinemachine properties in the inspector) and add a collider to the Bounding Shape 2D so that the cameras movement doesnt go beyond the boundaries of our collider we set in the scene. Make sure the collider is set to trigger.

Folliwing a Teleporting Player

If a player is being followed by a cinemachine camera and teleports suddenly, the cinemachine camera will then move erratically to keep up with the player which can be visually unpleasing. If you want the camera to teleport with the player without moving erratically, use the OnTargetObjectWarped(Transform, Vector3) method to notify the camera that the player transform has teleported with a position delta.