U
tab 03Camera & Input6 lessons — tap to open
03 / 06 · 8 min
Camera & Input

Cinemachine and camera shake

your project so far

Assets/

Scenes/

Arena.unity

CameraTargetCinemachineBrainCM vcamImpulse source / listenerOrbitCamera.cs→Cinemachine vcam

Project settings

Cinemachine package

you already havethis lesson addsthis lesson retires

Step three, and the last one. Cinemachine replaces both FollowCamera and OrbitCamera with components you configure — and it does collision, damping and blending better than the code you just wrote.

animated diagram

Same orbit idea, but damping, collision and target framing come built in.

Install and set up

  1. 1

    Window▸Package Manager▸Unity Registry → search Cinemachine → Install.

  2. 2

    GameObject▸Cinemachine▸Virtual Camera (Cinemachine 3: CinemachineCamera).

  3. 3

    Unity adds a CinemachineBrain to your Main Camera automatically. The brain is what actually drives the real camera.

  4. 4

    Set Follow = Knight and Look At = the Knight's CameraTarget on the virtual camera.

The mental model

  • Virtual cameras are not cameras. They are recipes: 'stand here, look there, with this much damping'.

  • The Brain on Main Camera picks the highest-priority active virtual camera and blends towards it.

  • Switching cameras is therefore just changing Priority or calling SetActive — the blend is free.

Third-person orbit in two clicks

  1. 1

    On the virtual camera set Body = Third Person Follow (or Orbital Follow in CM3).

  2. 2

    Set Camera Distance 6, Shoulder Offset X 0.5, Damping 0.3 / 0.3 / 0.3.

  3. 3

    Set Camera Collision Filter to your environment layers — wall clipping is now solved.

  4. 4

    Aim = Do Nothing if the rig already faces correctly, or Composer to keep the target framed.

✓ Hand-written camera

You learn how it works and control every line. Good for a small game.

✓ Cinemachine

Collision, damping, noise, blends, cutscenes — already solved and battle-tested.

Camera shake with Impulse

  1. 1

    Add a Cinemachine Impulse Listener to the virtual camera.

  2. 2

    Add a Cinemachine Impulse Source to whatever explodes or lands a hit.

  3. 3

    Call GenerateImpulse() from code and every listener in range shakes.

HitShake.cs
using UnityEngine;
using Unity.Cinemachine;      // Cinemachine 2: using Cinemachine;

public class HitShake : MonoBehaviour
{
    [SerializeField] private CinemachineImpulseSource source;

    public void Shake(float strength = 1f)
    {
        source.GenerateImpulseWithForce(strength);
    }
}

Switching cameras for a skill or cutscene

C# script
[SerializeField] private CinemachineCamera gameplayCam;
[SerializeField] private CinemachineCamera ultimateCam;

public void PlayUltimate()
{
    ultimateCam.Priority = 20;      // higher wins
    Invoke(nameof(BackToGameplay), 2f);
}

void BackToGameplay() => ultimateCam.Priority = 0;