Phase I: Camera Shake

Brian Branch
2 min readJun 1, 2021

In this article, I will explain one way to set up a camera shake when the player takes damage.

Objective: When the player takes damage, provide a subtle camera shake.

There are multiple ways to set up a camera shake in the game. My choice was to use animation to accomplish this objective.

First, I set up two animations, a Camera_Idle_anim and a Camera_Shake_anim, and set transitions between them.

Animator for Camera_Idle_anim and Camera_Shake_anim.

In the transition from the idle animation to the shake animation, I created a Trigger condition named Shake.

I then added a script to the Main Camera called CameraControl. Inside the script, I referenced the Animator, then in the Start() method, I performed a null check to make sure it’s not missing.

I then created a method named CamShake(), and all it does is activate the “Shake” trigger to transition to the Camera_Shake_anim when called.

Next, inside the Player script, I used a [SerializeField] to reference the camera then assigned it inside the Start() method.

Start() method also contains additional code not shown about for space constraint.

Then, inside the Player’s Damage() method, I add the following lines right after checking if the shield is active.

This assigns the variable cameraControl to the main camera, and if it is not null, it calls the CamShake() method on the CameraControl script.

You can see the results below.

Camera Shake in action.

That is how I set up the camera to shake when the player takes damage.

I hope you enjoyed reading the article and until next time, I wish you well on your coding journey.

--

--