In this lesson, you will learn how to trigger professional-grade camera shakes using the Cinemachine Impulse system to create visceral, localized feedback during gameplay events.
The Cinemachine Impulse Workflow
While procedural scripts can create basic shakes, Cinemachine Impulse provides a decoupled, event-driven architecture that feels much smoother and more cinematic. Instead of hard-coding camera movement, you create an Impulse Source that broadcasts a signal, and a CinemachineImpulseListener on your Virtual Camera that "hears" that signal and translates it into camera motion.
Setting Up the Impulse Source
To create a localized impact—like an explosion or a heavy footstep—you don't want the entire scene to shake; you want the shake to feel connected to an object.
- Add the Component: Add a
CinemachineImpulseSourcecomponent to your explosive object or player character. - Define the Signal: Inside the component, you will see an
Impulse Definitionfield. Create a newSignal Source. You can choose a preset like "6D Shake" or create a customSignal Shapeasset to define how the camera vibrates over time. - Triggering the Impulse: You can trigger the shake via code from your collision or explosion script. By calling
GenerateImpulse(), you notify the listener to begin the transition.
using Cinemachine;
using UnityEngine;
public class ImpactEffect : MonoBehaviour
{
public CinemachineImpulseSource impulseSource;
void OnCollisionEnter(Collision collision)
{
// Trigger the impulse at the point of contact
impulseSource.GenerateImpulse(collision.relativeVelocity);
}
}
Smoothing the Experience
The power of Cinemachine Impulse lies in its ability to handle Impulse Channels. By assigning a specific channel to your Impulse Source and ensuring your Virtual Camera's CinemachineImpulseListener is tuned to that same channel, you ensure that only the relevant cameras react to the event. This allows you to differentiate between a massive earthquake (global) and a localized enemy melee hit, ensuring your screen shakes are always purposeful, smooth, and physically grounded in the game world.
Key Takeaway: By using Cinemachine Impulse, you transition from rigid procedural movement to a modular, channel-based system that ensures camera shakes are context-aware, smooth, and highly performance-efficient.