In this lesson, you will learn how to trigger physical camera reactions like screen shakes using the Cinemachine Impulse system to make your gameplay collisions feel punchy and responsive.
The Core Concept: The Impulse System
Instead of manually animating a camera's position to simulate impact, we use the CinemachineImpulseSource component. Think of this as a "shaker" device you attach to any object in your scene, like a projectile or a breakable crate. When an event happens (like a collision), the source emits an "impulse signal" into the scene, which the CinemachineBrain on your camera detects and translates into screen shake.
Setting Up the Impulse Source
- Add the Component: Select the object that will trigger the effect (e.g., an explosive barrel) and add a
CinemachineImpulseSourcecomponent. - Define the Signal: In the component, assign an
Impulse Definition. You can use a built-inNoise Profile(like "Explosion" or "Rumble") to define how the camera should oscillate. - Triggering via Script: You don't need a complex state machine for this. You simply call the
GenerateImpulse()method on the source when your collision logic runs.
Example: Triggering on Collision
Here is how you would trigger a screen shake when your object hits something:
using UnityEngine;
using Cinemachine;
public class CollisionShake : MonoBehaviour
{
private CinemachineImpulseSource impulseSource;
void Start()
{
impulseSource = GetComponent<CinemachineImpulseSource>();
}
void OnCollisionEnter(Collision collision)
{
// Generate the impulse signal
impulseSource.GenerateImpulse();
}
}
Why Use This Instead of Manual Animation?
Because Impulse Sources are decoupled from your camera’s animation state, they are perfect for one-off reactive events. You don't need to worry about complex Animator layers or Blend Trees to handle a simple shake. The system automatically manages the decay of the shake and allows you to easily scale the intensity based on the speed of the collision, ensuring your cinematic feedback remains high-quality without polluting your Animator state machines.
Key Takeaway: Cinemachine Impulse Sources allow you to add reactive, physics-based camera effects to your game by emitting signals that the camera brain automatically translates into dynamic screen shakes.