Shake, Shake, Shake, Senora!

Ryan Sweigart
May 8, 2021

When the player takes damage, we want things to be a little more exciting than simply decreasing a section of their life bar. Let’s add a camera-shaking effect!

“Ow, my pancreas.”

We do this with a public method and a simple timer. When the player takes damage, it calls the camera’s public Shake method. All this method does is set a timer. The magic is in the Update method. If the timer has a value greater than 0, we move the camera to a new random position within a sphere and decrease the timer. If the timer is at 0 or less, we return the camera to its original position.

This little bit of code gives us a really cool effect!

--

--