Spice Up Your Game with Screen Shake
If you’re looking to create a more immersive, satisfying experience, game feel is one of the first places to start.
💥A Guide to Screen Shake
Let’s start with Screen Shake. This is one of the easiest and best ways to juice up your game quickly and I find myself using it again and again. Without further ado, let me introduce to you my universal camera shaker.
This script can be drag & dropped into your project. It and many more can all be found over on GitHub. Feel free to use them in any of your games!
So why is Screen Shake so useful? Firstly, it’s satisfying. We want our core mechanics to feel great. Screen Shake adds that extra bit of impact when firing a gun or landing in a platformer. Second of all, Screen Shake helps create immersion and places us right in the action. A fantastic way to get us in the flow state, this effect connects us with the action on screen.
Let’s dive into the code and see how this script works.
First up, we’re using the Unity Cinemachine Package. This is a great tool for all your camera control needs: today we’ll be using it to shake our camera. To achieve this we’re going to use the Noise feature of a Cinemachine camera.
The basic shake works by enabling this noise, which will move and rotate our camera based on Perlin noise. After our shake duration we can set the noise intensity (known as amplitude) back to zero.
The Smooth Shake function builds on this. We can use the Math.Lerp function in order to fade our shake in and out. A basic shake works just fine but if you want a bit more customization, try this one out!
Ok, with that explanation out of the way, let’s explore how you can add this to your project.
Step-by-step Guide
In Unity, install the Cinemachine package from the Package Manager window.
Right-click in the hierarchy and, under Cinemachine, create a new Virtual Camera (or 2D Camera)
Near the bottom of the Cinemachine Virtual Camera component find Noise. Set this to Basic Multi Channel Perlin
Finally, add the Camera Shaker script to an object in the scene
That's everything! Call the Basic or Smooth Shake function whenever you want some Camera Shake.
Feel free to comment any questions below.
🎉Have a great week,
Adam