Nerd For Tech
Published in

Nerd For Tech

Shaking things up in our camera

Today we will be looking at creating an indicator for when our player takes damage aside from the burning thrusters. What we will look at implementing is a camera shake method. First, let’s go to our Player script and create a new variable to attach our camera to:

From here, we will create a new Coroutine within our player script that will enact our camera shake:

First, we will enter in a vector 3 for our camera to reset to once we have completed our shake method. In this instance, we will use a for loop to create the shake. From here, we will enter in our camera shake distance to work with on both the x and y axis. After we close the method, we will want to be sure to put the camera position back to our main position, otherwise we will have our games camera off center and there will be black edges showing up at the ends of our playing area. Once we have it all put in, we can go back to our game and see how it looks and adjust our values if we want to have it have more or less shaking:

--

--

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