Phase I — Progress report — Camera shake
This update is going to show you how to quickly set up a camera shake in Unity using Cinemachine.
The first step is to install Cinemachine. So go to Window > Package Manager > Unity Registry and install Cinemachine.
The next step is to create a virtual camera. Go to Cinemachine > Create Virtual Camera.
This camera will override your main camera so you will have to manually copy the transforms across. If you want to re-name the camera you can.
Now, let's add an impulse listener to our virtual camera. This will allow the camera to listen for events that we are going to create later.
You can create your own noise profile to use but I just copied the 6D shake profile so I can adjust that one if I wanted to. You can copy the noise profile by going go to the Noise drop down on the virtual camera and selecting Basic Multi-Channel Perlin then changing the profile to 6D Shake. You can click the cog icon and click copy. You can rename your profile to whatever you like and pick where to save the asset. I’m calling mine medium shake.
Now we can add some unity events. I added them to my player script by adding the namespace “UnityEngine.Events;”. Then we can create a Unity event, I’ll call mine medium shake.
We just need a function to invoke the event now which for testing purposes I’ll trigger when I press the control key.
Now we need to add a listener for the event. I created a new game object called CameraShakeManager and added an impulse source to it and assigned our noise profile to the Raw signal reference.
Next, we need to assign our camera shake manager to our event. Go back to the player object and add a new event using the “+” button under our medium shake event. Now drag in the camera shake manager and choose the function “Cinemachine Impulse Source” > “Generate Impulse”
Now we test our results, I’ve increased the values and length so it will be easier to see.