‫So we'd like the camera to shake once our projectile hit, something like that.
‫And we'd also like it to shake once one of our ponds dies.
‫Hey, welcome back.
‫In this video, we're going to add another special type of effect to our game involving shaking the
‫camera.
‫We'd like to shake the camera when the projectile hits something, as well as when one of our ponds
‫dies.
‫This will add just another bit of a finishing touch to the game that will make it feel a bit more professional.
‫So let's dive in now.
‫Here we are inside the editor and I'd like to add a new class for our camera shake.
‫Unreal Engine has a built in class for shaking the camera.
‫Now I'm going to make a new folder here in the blueprints folder and call this camera shake.
‫And in the camera shake folder.
‫I'm going to right click and create a new blueprint.
‫The reason we're making a blueprint is because this is one of those things that's a lot easier to make
‫from the blueprint side, as there are lots of variables to adjust with camera shakes, and the class
‫we're looking for is matinée camera shake so we can search for camera shake and choose.
‫Matinée camera shake.
‫Click Select and we'll call this first camera shake.
‫BP Hit Camera Shake.
‫Now let's double click this new blueprint and open it up and we'll see that it has a details panel with
‫lots of different variables to choose from.
‫And let's talk about some of these parameters that exist in the camera shake class.
‫Now, there are quite a few here, and we're only going to touch on a couple that affect the overall
‫feel of the camera shake.
‫Now you'll see that there's a section called oscillation.
‫And the reason this section is called oscillation is because a camera shake involves oscillating the
‫camera.
‫Now, here's the Wikipedia page for a sine wave.
‫A sine wave is a mathematical function, and we don't need to understand the math behind a sine wave.
‫But it does help to see what a sine wave looks like.
‫If I scroll down right here to the right, I see this red wave here and it's labeled sine a sine wave
‫oscillates.
‫That means it goes up and down or back and forth.
‫So if our camera is being jerked back and forth in a smooth manner, we say that it's oscillating.
‫Now we see that we have an oscillation duration and a blend in time and a blend out time.
‫The duration affects how long the shake is going to last.
‫Now, these are values that you can experiment with, but I've already done some experimenting and I
‫know some good ballpark values for the hit camera shake.
‫When the projectile hits something, we're going to have a relatively short duration.
‫Now, this is in seconds, and I'm going to choose 0.2 5 seconds for the duration of this camera shake
‫and for the blend in and blend out time.
‫I'm going to use values of 0.05, so 0.05 for blend in time and 0.05 for the blend out time.
‫This is how long it takes to blend in and out of the camera shake, which will last for 0.2 5 seconds.
‫Now we have different types of oscillations.
‫We have rotational oscillations, and these will rotate the camera according to that oscillation function.
‫We have a location oscillation which will jerk the camera around in space and a field of view oscillation,
‫which will affect the field of view, which is basically zooming in and out with the camera.
‫Now, rotation and field of view oscillations are the ones that are more prone to causing motion sickness.
‫So you can experiment with those if you like.
‫But for this camera shake, we're just going to change the location oscillation.
‫Now we have three axes X, Y and Z, and we saw that the sine wave will jerk something back and forth.
‫These oscillations will jerk the camera back and forth in the X, Y and z directions.
‫I'm going to click these dropdowns to expand them and we'll see that each axis has an amplitude, a
‫frequency, as well as an initial offset and a waveform.
‫Now the initial offset for the camera shake is set to random, and we can leave that at random so that
‫we have less of a predictable camera shake.
‫And the sine wave is the type of waveform used when jerking the camera.
‫And we saw that it has a smooth up and down motion.
‫Now amplitude is the maximum amount of movement in that axis that the camera will move.
‫I'm going to set these all three to have amplitudes of ten, an X, Y and z and frequency is going to
‫be how fast the camera oscillates.
‫I'm going to set these also to be ten.
‫Now we'll get to see just how this looks as soon as we implement the camera shake.
‫But before we do that, I'm going to create another camera shake and this will be for when the pawn
‫dies.
‫So let's right click, create a new blueprint class and search for camera shake and select matinée camera
‫shake, click select.
‫And for this, we're going to call this BP Depth Camera Shake.
‫Now the death camera shake is going to be a little bit more violent than the hit camera shake.
‫The hit camera shake will shake the camera when our projectile hit something.
‫But the death camera shake is going to shake the camera when something dies.
‫So for the oscillation duration, I'm going to make this a bit longer.
‫I'm going to go 4.3, 5 seconds and four, blend in time and out time.
‫I'm going to set these both to 0.1.
‫Now, just a side note blend in and out time.
‫Are percentages of the full time normalized between zero and one?
‫So point one is 10% of the full oscillation duration.
‫Now I'm going to set the amplitudes to 54 X and Y and I'm going to leave the Z amplitude at zero so
‫that we only jerk the camera in X and Y upon -- death.
‫This way we'll get a bit of a different looking camera shake.
‫And for the frequency, I'm going to set these both to 20.
‫So we now have a camera shake and it's time to implement actually playing these camera shakes from the
‫C++ side.
‫Now in order to play a camera shake, we need some camera shake variables.
‫If you're using an older version of Unreal Engine, Unreal Engine 4.25 and below specifically, then
‫the class for your variables is going to be you.
‫Camera shake.
‫But in newer versions 4.2, six and above.
‫And this includes Unreal Engine five.
‫We're going to use you matinee.
‫Camera shake.
‫So that's what we're going to use in this video.
‫Now, the functions to play a camera shake are different as well.
‫If you're on 4.2, five and below, then the function you're going to use is client play.
‫Camera shake.
‫And this is a function on the player controller class now in 4.26 and above, including 5.0, which
‫is what we're using.
‫We're going to use client start camera shake as client play.
‫Camera shake is now deprecated.
‫So since we're using Unreal Engine five, we'll be using clients, start camera shake.
‫And if you're using five, you're going to follow along and use clients start camera shake.
‫But for older engine version, specifically 4.2, five and below, use the class and the function on
‫the left side there and everyone else use the class and function on the right.
‫Now just to show you, here's you camera shake base in the documentation and here is the include for
‫it.
‫So you're going to use this camera slash camera shake base for the include.
‫So first, I'd like to handle the hit camera shake in the projectile class.
‫So here in projectile, I'm going to add a camera shake.
‫Now, this will be forward declared.
‫I'm going to make a U.
‫Camera shake base.
‫It's a pointer.
‫And I'm going to call this hit camera shake now because I'd like to set this from blueprints.
‫Since we have a camera shake blueprint, I'm going to expose this.
‫It's going to be a new property.
‫I'm going to make it edit anywhere and give it a category.
‫And for this, I'll keep it in the combat section.
‫Now I'm ready to play the camera shake.
‫So in projectiles CP, I'm going to place this in on hit here in the check for other actor.
‫And the first thing I'm going to do is make sure that I've set the camera shake from blueprints, which
‫means I need to make sure that hit camera shake is not null.
‫So if I hit camera shake, then I can start the camera shake.
‫And here's a player controller client start camera shake for the versions 4.26 and above.
‫Now notice a couple of things.
‫These involve tw subclass of variables, which means we need a new class.
‫Now we created blueprints for these variables, which means we can easily create a subclass of rather
‫than a regular variable here.
‫So I can take this class you camera shake base and put it inside a PT subclass of so let's say PT subclass
‫of and I'm going to keep the forward declaration here and I don't need the asterisk since PT subclass
‫of just wraps this up in the template and because this hit camera shake is actually a PT subclass of
‫I'm going to call it hit camera shake class and now in projectile that CPP rather than hit camera shake
‫let's call this hit camera shake class and now we can call a client start camera shake.
‫Now this function belongs to the player controller and we're here in projectile CP and we don't have
‫a variable for the player controller, but we have this function get first player controller which exists
‫on the U world class so we can call get world and then call get first player controller.
‫So we're going to do that.
‫So first we'll call Git World and from there we're going to call get first player controller and from
‫get first player controller, we can call a client start camera shake and we'll see that this takes
‫a PT sub class of we're going to pass in hit camera shake class and the rest of these input parameters
‫have default values so we can omit the remaining inputs.
‫So let's go ahead and compile this.
‫So back here in the editor, we're ready to test this out.
‫Now we created the blueprint and the PT sub class of but we need to set that PT sub class of.
‫So let's go into actors and BP projectile.
‫I'm going to open the full blueprint editor and go to the combat section and here's my hit camera shake
‫class t sub class of I can open this and select hit camera shake and now this will be set.
‫So I'm going to compile press play and let's see if we get that camera to shake.
‫And there it goes.
‫Awesome.
‫So next, I want to play a camera shake when the pod dies.
‫So I'm going to go into bass pond and add a camera shake variable here.
‫So down here at the bottom, let's make another t subclass of variable.
‫I'm going to forward declare it.
‫It's going to be you camera shake base and I'm going to call this depth camera shake class.
‫And just like our other one, we're going to make this a U property.
‫Edit Anywhere Category combat and now we have a camera shake class here in base pon.
‫Now I'm going to challenge you to play the death camera shake for the pawn when it dies.
‫So you're going to do this when the -- dies and that's going to be in handle destruction, of course.
‫So choose the correct location in this function to play this camera shake and then compile your code.
‫Set the sub class of value in both the tank and tower blueprint classes and test it out.
‫Pause the video and implement the death camera.
‫Shake now.
‫Okay.
‫So we have our def camera shake class.
‫Let's go into base pond CP and I'm going to scroll up to handle destruction.
‫And the first thing I'm going to do is check to make sure depth camera shake class is set and if it
‫is, then we can actually play the camera shake.
‫Now we don't have a pointer to the player controller here, so I'm going to call Get World from here,
‫get first player controller and from there I'm going to call.
‫Client start camera shake.
‫And in here we can pass in depth camera, shake class.
‫And there we have it.
‫So let's compile this and we'll hop back into the editor and I'm going to open the --'s folder, BP
‫-- tank.
‫And here we have depth camera shake class.
‫I'm going to set this to death.
‫Camera, shake, compile and save and close.
‫I'm going to close the projectile as well.
‫And open BP pond, turret and set depth camera shake class to depth camera shake here as well.
‫Now we can test out death.
‫So let's see how this works.
‫Kay, I'm going to go up to one of the towers and.
‫Boehm.
‫The camera shake works.
‫Now, the last thing to check is if we get the camera shake when the towers die.
‫So let's go ahead and kill one of the towers.
‫And there we go.
‫We got the camera to shake.
‫Awesome.
‫So in summary, we are now shaking the camera.
‫We're shaking it when the projectile hit something and when one of the ponds dies.
‫This is just another one of those nice polish up effects that makes our game look a bit more professional.
‫Speaking of polishing up in our next video, we're going to polish up the game and get it in its final
‫working state so we can wrap up this section and have a complete working game under our belts.
‫I'll see you soon.