Shell Shock: Camera Effect on Damage (Game Dev day 39)

Jack Leavey
2 min readSep 26, 2021

Objective: Provide a subtle camera shake when the player takes damage.

Currently there are two forms of feedback to alert the player that they have taken damage; the Lives UI updates and a visual effect on the Player’s controllable ship as well.

Player at 3 lives
Player after being hit once

To make sure the player is aware that they have been damaged, I added a camera shake when the damage function plays.

I created a new script called CameraShake and attached it to the Main Camera Gameobject.

Next, I wrote out the logic to rapidly move the main camera in a random direction on both the X and Y axes. As this is a 2D game, I left the Z axis as is. this coroutine is set to public so it can be referenced from the Player script later.

Next, to ensure that the camera returned to its proper location after the Camera shake I created an Empty GameObject called the Camera Anchor. I made sure it had the exact same position in the game as the Main Camera, and then I made the Main Camera a child of the Camera Anchor.

All that’s left is to call this coroutine during the Damage function on the Player script.

Added Line 210
Each instance of damage shakes the camera for a moment.

--

--

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!