Cinemachine: Camera Shake On Collisions
Intro
In this article, we are going to cover how to create a camera shake based on a collision.
Cinemachine Collision Impulse Source
The first thing is to add a Cinemachine Collision Impulse Source component to the object that will cause the camera shake.
The Impulse Source needs a Signal Source which creates how the camera will move on the X, Y & Z axis. Read my previous article, which covers creating Signal Sources.
Cinemachine Impulse Listener
You will need to add an extension to the camera you want to shake when it collides with the object that has the Impulse Source.
The extension is Cinemachine Impulse Listener, which detects an Impulse Source and will move the camera based on the Signal Source.
Layers & Tags
You can set the Impulse Source to only send the signal to objects in a certain layer and you can have the signal ignored in that layer with a certain tag.
Back to the object with the Cinemachine Impulse Listener, and make sure it is in the same Layer as the Impulse Source.
Every time we run into the object with the Cinemachine Collision Impulse Source the camera now shakes.