There is another useful extension in Cinemachine can allow you to create the camera shake effect, which is quite common to use in games these days.
Camera shake can provide a realistic feeling that would decrease the distance between players and games. For example, camera shakes when players got hit by bullets or fire a weapon in hands.
Using Impulse Listener
As adding storyboard extension, select Impulse Listener from dropdown menu.
Next we need to add an impulse source that would handle the shaking effect.
Create an empty object, then add a component called “Cinemachine Impulse Source”.
As you can see, there is a warning sign to tell you that you would need a signal source asset to make this works. Let’s create one in Project window.
Add one from New> Cinemachine> NoiseSettings.
Then select the Noise Settings, you can adjust the data of noise from Inspector like frequency and amplitude of 3 axis.
Take is easy at this part because you can still adjust the shaking effect from the Impulse Source component.
Now back to Impulse Source gameobject, assign the NoiseSettings to Impulse Source component. Here are some values that you can easily to change during the gameplay to check the best result.
For example, there are 3 values under Time Envelope: Attack, Sustain TIme, and Decay. These can make a realistic gunfire shake if you make a perfect setting.
Now we got the settings, it’s time to create a script to demonstrate the camera shaking effect.
Create a script with easy function to cause the shake.
First, we need to use the library of Cinemachine.
Then we need to create a variable of Cinemachine Impulse Source. Then assign it to the component at Start().
Let’s create a new function to handle the camera shake.
When calling the impulse source, it should automatically listed all the possible options. Choose GenerateImpulse.
Now we can call this function from Update() with any input that your want.
Back to Unity and attach this script to Impulse Source gameobject.
If the result is not the best to you, you can always change the setting in Impulse Source.
Import this script into pistol trigger or katana attacking button, you would get a decent attacking camera shake effect.