Skip to main content

Cinemachine

Cinemachine is a powerful tool for using cameras in Unity. This package is installed by default in the Genies Dev Kit and ready to use.

Here are some popular use cases:

  • Create a 3rd person camera following the player
  • Create a cut scene
  • Blend from one camera to another
tip

Read Unity's Cinemachine Manual for more information.

Adding Cinemachine Cameras

To add a cinemachine camera, right click in the Hierarchy window. Select the Cinemachine section and choose one of the several options of cameras.

Add Cinemachine

Creating a 3rd Person Camera

A 3rd person camera is useful for most games so the camera follows the player as it moves around.

tip

The Character Controller tool includes a third person example that uses Cinemachine cameras.

Steps to Add

Add a Virtual Camera

Add a Virtual Camera to the Hierarchy. In the Inspector window, set the Look At and Follow property to the player Game Object reference. The camera will now follow the player as it moves.

Cinemachine Inspector

Add a Collider

The Virtual Camera object can add extensions to the component. In the Inspector window, click the Add Extension dropdown at the bottom and select CinemachineCollider. This will attempt to fix an issue if the camera is ever blocked by another object from seeing its target.

Cinemachine Collider

TypeScript Usage

Package

The Cinemachine API can be accessed by importing the package, like so:

import { CinemachineVirtualCamera } from "Cinemachine";

Example

Here is an example of using TypeScript with the Cinemachine API to make a cutscene between two cameras:

import { Mathf, MonoBehaviour, Time } from "UnityEngine";
import { CinemachineVirtualCamera } from "Cinemachine";

export default class MyScript extends MonoBehaviour {

@Header("Cinemachine Settings")
@SerializeField private startCam: CinemachineVirtualCamera;
@SerializeField private endCam: CinemachineVirtualCamera;
@SerializeField private transitionTime: number = 5;

private elapsedTime: number = 0;

private Start() : void {
if (this.startCam != null)
{
this.startCam.Priority = 1;
}

if (this.endCam != null)
{
this.endCam.Priority = 0;
}
}
private Update() : void {
if (this.elapsedTime < this.transitionTime)
{
this.elapsedTime += Time.deltaTime;
let blend = Mathf.Clamp01(this.elapsedTime / this.transitionTime);

this.startCam.Priority = Mathf.RoundToInt(1 - blend);
this.endCam.Priority = Mathf.RoundToInt(blend);
}
}
}