How to Make the Camera Shake Using Impulse Listener Extensions in Cinemachines Virtual Cameras

Objective: Let’s make the camera shake using Cinemachines Impulse Listener Extension.

Camera Shake

Have you ever wanted to create a lightweight camera shake that doesn’t involve much code at all? Then let’s take a look at Cinemachines answer to that!

What is the Impulse Listener Extension in Cinemachine?

This extension gives the virtual camera the ability to ‘listen’ to impulse vibration signals and react to them in a specific way.

Depending on how we set this up, it could be something very basic that provides a very subtle short screen shake when a player falls from a small distance or something as large as an earthquake creating a much larger, lengthier and generally more intense shake as it plays out.

How to Get this Setup

First, let’s add the Impulse Listener Extension to the virtual camera. While having the virtual camera highlighted, scroll down to the bottom of the CinemachineVirtualCamera component and click Extension → Add Extension → Impulse Listener:

Adding the Impulse Listener Extension to the virtual camera

Now this component is only looking to hear for the signal noises that are being emitted, so we need to set something up that is going to play the signal noise also.

Let’s Create Some Noise

Create a new empty game object and call it ‘Impulse’.

Next, we are going to add a new component to it called ‘Cinemachine Impulse Source’ which should look like this when it is attached:

Cinemachine Impulse Source

Now as you can see we have a small error pop up and that is letting us know that this field is looking for a specific type of asset called a ‘Signal Source Asset’. So let’s create one and get that added in.

Right click in the project window, Create → Cinemachine → Noise Settings. We can now add this asset to the field and start to play around with some of the settings.

Noise Settings Asset

Noise Settings in the Inspector

If we open up the Position X and Y by clicking on the small arrows next to them, you can now see that we have these boxes that are looking for components. So let’s hit the ‘+button and you will see that it has created 2 new fields and a checkbox. These are the ‘Frequency’, ‘Amplitude’ and ‘Random Wave’. Frequency refers to how often we want the sound waves to happen, while amplitude is how high and low the curves are along the wave. If we were to tick that check box it would give us a perfect wave as shown:

Tick box checked for a perfect wave
Unchecked tick box creating a random wave incorporating the frequency and amplitude

Let’s Do Some More Adjusting of Settings

On the CinemachineImpulseSource component let’s play around with a few of the ‘Time Envelopesettings:

CinemachineImpulseSource component — Time Envelope settings

Attack —This refers to how the signal reaches its full amplitude. This field takes a curve or straight line parameter, defining how it should ramp up to it’s peak amplitude, and how many seconds should it take to get there.

Attack Curve

Sustain Time — This refers to how long the shake will sustain itself when it reaches it’s peak amplitude.

Decay Similar to the attack, it takes a curve or straight line parameter with seconds, telling it how long it should come down from its peak to 0.

Create a Basic Script to Generate an Impulse

Now we just need literally a few lines of code to generate an impulse, using a built in method:

Just simply attach this script to the impulse game object.

Testing

Now, let’s run the game and press the ‘Spacekey and see if the screen shakes!

Shaking Camera!

--

--

--

Passionate Unity Game Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fun lil’ Animation on Scroll; REACT!

DSA #2: Linked List

How To Use React Router To Improve The UX Of Your React Application

Angular’s imminent version 8 has been transpired!!! Explore the novel features — Ivy and others.

Your Life FA2 by RSM Marketing

Understanding NaN, isNaN() and Number.isNaN()

(Ab)using package.json over index.js

Top 10 Full Stack Development Tools You Cannot Ignore in 2021

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Hilton

Chris Hilton

Passionate Unity Game Developer

More from Medium

Using the Animation Override Track in Timeline

Enable Ads In Unity!

Working with Screen Space Reflections in Unity’s HDRP

Installing the Universal Render Pipeline in Unity 2021.2