Unity’s Cinemachine: Impulse Listener Extension
Hello all!
Today, I will be going over adding the impulse listen extension and why!
Implementing the Impulse Listener to a Camera
There will be three things we have to do before this works:
Adding the extension to the virtual camera
- Select the virtual camera you need.
- At the bottom of the Inspector, add the CinemachineImpulseListener extension.
- The settings here are enabled after listening to an impulse, so you may not need to mess with things here.
Creating an Impulse Source
We need the source for things like explosions that occur around you. You wouldn’t want an explosion across the scene to shake your camera, so these should be added as a child to anything you want to shake the camera.
- Create an empty gameobject and name it something like Recoil_Impulse.
- Add the component Cinemachine Impulse Source.
Now, let’s explain what’s going on here:
- Impulse Types:
- Uniform: Will happen the same regardless of distance.
- Dissipating: Think of an explosion, the further away you are, the less you will feel it.
- Propagating: This is like a wave of destruction. Much like an earthquake - Impulse Shape: There are multiple options here, but they all simulate real behavior!
- Default Velocity: Changes the force of each axis.
- Test with Force: The higher the value, the harder it shakes. The testing feature here is nice because you can test it without script.
Now let’s add Code to Activate the Impulse
At the top of the Impulse Source component, it asks you to call this source using GenerateImpulse in code. Here’s how:
Create a C# script, name it something similar to the source, then attach it to wherever you need it. Regardless, you will need to call the component.
- When doing this, don’t forget to add the Cinemachine namespace at the top!
When you call the GenerateImpulse method, it should generate noise on your camera!
That was how to implement impulse listeners to your camera!
Next up, adding the post processing extension to your virtual camera.
Thank you for your time!