48-Camera Shake upon Player Damage

This post will add a camera shake effect when the player is damaged by the enemy.

To do so, first, we need to script a camera shake function for the main camera. Note that this behavior will repeat itself for a small amount of time, a coroutine will be introduced.

The factors that need to be considered are the shaking magnitude and the shaking duration. Essentially, the shaking behavior involves changing the camera’s position (randomly) within a certain time frame.

After creating a public coroutine for the camera, we can then call this routine in the Player script when damage occurs.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store