Cinemachine and camera shake
Assets/
Scenes/
Arena.unity
Project settings
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.
Same orbit idea, but damping, collision and target framing come built in.
Install and set up
- 1
→ search Cinemachine → Install.
- 2
(Cinemachine 3: CinemachineCamera).
- 3
Unity adds a CinemachineBrain to your Main Camera automatically. The brain is what actually drives the real camera.
- 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
On the virtual camera set Body = Third Person Follow (or Orbital Follow in CM3).
- 2
Set Camera Distance 6, Shoulder Offset X 0.5, Damping 0.3 / 0.3 / 0.3.
- 3
Set Camera Collision Filter to your environment layers — wall clipping is now solved.
- 4
Aim = Do Nothing if the rig already faces correctly, or Composer to keep the target framed.
✓ Hand-written camera
✓ Cinemachine
Camera shake with Impulse
- 1
Add a Cinemachine Impulse Listener to the virtual camera.
- 2
Add a Cinemachine Impulse Source to whatever explodes or lands a hit.
- 3
Call GenerateImpulse() from code and every listener in range shakes.
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
[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;