Phase 1: Camera Shake

Simon Leen
2 min readJun 21, 2021

Objective: Add a camera shake effect when the player is hit.

For the camera shake we will create a CameraShake script and attach it to the Main Camera. We will use a simple coroutine to move the camera in small adjustments left and right, up and down very quickly and then return the the starting point.

Camera Shake Coroutine

Next on the player script, create a private CameraShake and assign it in the Start method using the Camera.main GetComponent and remember to null check. Inside the players TakeDamage method call the CamShake coroutine but unlike a normal method call, we are calling a coroutine so remember to start the coroutine when making the calling.

Start Coroutine while calling the method

To add a little spice to the shake, we will use the Post Processing Volume to add a little color when hit. In the player script, create a serialized private PostProcessVolume and remember to import the necessary namespace(using UnityEngine.Rendering.PostProcessing). We will adjust theColor grading and Bloom so, create a private entry for both.

Post Processing variables

Now set the profile connections in the Start method.

Post processing profile connections

We will then use another coroutine triggered at the same time as the camera shake and adjust the temperature and tint of the color grading along with the intensity of the bloom before going back to the settings we chose when setting up the Post Processing.

Coroutine for Post Processing manipulation
Camera Shake with Post Process Red Flash

In the next post, we will clean up the UI and add some more elements for powerup display.

--

--