﻿1
00:00:04,380 --> 00:00:09,780
‫So we'd like the camera to shake once our projectile hit, something like that.

2
00:00:09,780 --> 00:00:13,680
‫And we'd also like it to shake once one of our ponds dies.

3
00:00:14,040 --> 00:00:15,460
‫Hey, welcome back.

4
00:00:15,480 --> 00:00:22,140
‫In this video, we're going to add another special type of effect to our game involving shaking the

5
00:00:22,140 --> 00:00:22,950
‫camera.

6
00:00:22,950 --> 00:00:28,890
‫We'd like to shake the camera when the projectile hits something, as well as when one of our ponds

7
00:00:28,890 --> 00:00:29,670
‫dies.

8
00:00:29,700 --> 00:00:36,480
‫This will add just another bit of a finishing touch to the game that will make it feel a bit more professional.

9
00:00:36,480 --> 00:00:38,610
‫So let's dive in now.

10
00:00:38,610 --> 00:00:45,060
‫Here we are inside the editor and I'd like to add a new class for our camera shake.

11
00:00:45,060 --> 00:00:49,440
‫Unreal Engine has a built in class for shaking the camera.

12
00:00:49,440 --> 00:00:55,590
‫Now I'm going to make a new folder here in the blueprints folder and call this camera shake.

13
00:00:55,590 --> 00:00:57,630
‫And in the camera shake folder.

14
00:00:57,630 --> 00:01:00,450
‫I'm going to right click and create a new blueprint.

15
00:01:00,480 --> 00:01:05,580
‫The reason we're making a blueprint is because this is one of those things that's a lot easier to make

16
00:01:05,580 --> 00:01:12,900
‫from the blueprint side, as there are lots of variables to adjust with camera shakes, and the class

17
00:01:12,900 --> 00:01:18,060
‫we're looking for is matinée camera shake so we can search for camera shake and choose.

18
00:01:18,060 --> 00:01:20,160
‫Matinée camera shake.

19
00:01:20,980 --> 00:01:24,790
‫Click Select and we'll call this first camera shake.

20
00:01:25,060 --> 00:01:27,890
‫BP Hit Camera Shake.

21
00:01:27,910 --> 00:01:34,240
‫Now let's double click this new blueprint and open it up and we'll see that it has a details panel with

22
00:01:34,240 --> 00:01:37,300
‫lots of different variables to choose from.

23
00:01:37,310 --> 00:01:42,350
‫And let's talk about some of these parameters that exist in the camera shake class.

24
00:01:42,370 --> 00:01:48,160
‫Now, there are quite a few here, and we're only going to touch on a couple that affect the overall

25
00:01:48,160 --> 00:01:49,880
‫feel of the camera shake.

26
00:01:49,900 --> 00:01:53,140
‫Now you'll see that there's a section called oscillation.

27
00:01:53,140 --> 00:01:59,710
‫And the reason this section is called oscillation is because a camera shake involves oscillating the

28
00:01:59,710 --> 00:02:00,430
‫camera.

29
00:02:00,670 --> 00:02:04,370
‫Now, here's the Wikipedia page for a sine wave.

30
00:02:04,390 --> 00:02:11,650
‫A sine wave is a mathematical function, and we don't need to understand the math behind a sine wave.

31
00:02:11,650 --> 00:02:14,850
‫But it does help to see what a sine wave looks like.

32
00:02:14,860 --> 00:02:23,230
‫If I scroll down right here to the right, I see this red wave here and it's labeled sine a sine wave

33
00:02:23,260 --> 00:02:24,010
‫oscillates.

34
00:02:24,010 --> 00:02:26,920
‫That means it goes up and down or back and forth.

35
00:02:26,920 --> 00:02:33,610
‫So if our camera is being jerked back and forth in a smooth manner, we say that it's oscillating.

36
00:02:33,610 --> 00:02:39,940
‫Now we see that we have an oscillation duration and a blend in time and a blend out time.

37
00:02:39,940 --> 00:02:44,620
‫The duration affects how long the shake is going to last.

38
00:02:44,650 --> 00:02:50,140
‫Now, these are values that you can experiment with, but I've already done some experimenting and I

39
00:02:50,140 --> 00:02:53,560
‫know some good ballpark values for the hit camera shake.

40
00:02:53,560 --> 00:02:58,270
‫When the projectile hits something, we're going to have a relatively short duration.

41
00:02:58,330 --> 00:03:05,470
‫Now, this is in seconds, and I'm going to choose 0.2 5 seconds for the duration of this camera shake

42
00:03:05,470 --> 00:03:08,080
‫and for the blend in and blend out time.

43
00:03:08,080 --> 00:03:18,220
‫I'm going to use values of 0.05, so 0.05 for blend in time and 0.05 for the blend out time.

44
00:03:18,340 --> 00:03:25,360
‫This is how long it takes to blend in and out of the camera shake, which will last for 0.2 5 seconds.

45
00:03:25,390 --> 00:03:28,330
‫Now we have different types of oscillations.

46
00:03:28,330 --> 00:03:35,500
‫We have rotational oscillations, and these will rotate the camera according to that oscillation function.

47
00:03:35,500 --> 00:03:42,430
‫We have a location oscillation which will jerk the camera around in space and a field of view oscillation,

48
00:03:42,430 --> 00:03:48,130
‫which will affect the field of view, which is basically zooming in and out with the camera.

49
00:03:48,160 --> 00:03:54,700
‫Now, rotation and field of view oscillations are the ones that are more prone to causing motion sickness.

50
00:03:54,700 --> 00:03:57,700
‫So you can experiment with those if you like.

51
00:03:57,700 --> 00:04:03,100
‫But for this camera shake, we're just going to change the location oscillation.

52
00:04:03,130 --> 00:04:10,300
‫Now we have three axes X, Y and Z, and we saw that the sine wave will jerk something back and forth.

53
00:04:10,300 --> 00:04:16,210
‫These oscillations will jerk the camera back and forth in the X, Y and z directions.

54
00:04:16,210 --> 00:04:22,540
‫I'm going to click these dropdowns to expand them and we'll see that each axis has an amplitude, a

55
00:04:22,540 --> 00:04:26,740
‫frequency, as well as an initial offset and a waveform.

56
00:04:26,740 --> 00:04:33,460
‫Now the initial offset for the camera shake is set to random, and we can leave that at random so that

57
00:04:33,460 --> 00:04:36,310
‫we have less of a predictable camera shake.

58
00:04:36,310 --> 00:04:41,110
‫And the sine wave is the type of waveform used when jerking the camera.

59
00:04:41,110 --> 00:04:45,070
‫And we saw that it has a smooth up and down motion.

60
00:04:45,070 --> 00:04:51,450
‫Now amplitude is the maximum amount of movement in that axis that the camera will move.

61
00:04:51,460 --> 00:04:59,680
‫I'm going to set these all three to have amplitudes of ten, an X, Y and z and frequency is going to

62
00:04:59,680 --> 00:05:02,800
‫be how fast the camera oscillates.

63
00:05:02,800 --> 00:05:05,650
‫I'm going to set these also to be ten.

64
00:05:05,740 --> 00:05:10,840
‫Now we'll get to see just how this looks as soon as we implement the camera shake.

65
00:05:10,840 --> 00:05:16,900
‫But before we do that, I'm going to create another camera shake and this will be for when the pawn

66
00:05:16,900 --> 00:05:17,680
‫dies.

67
00:05:17,680 --> 00:05:25,540
‫So let's right click, create a new blueprint class and search for camera shake and select matinée camera

68
00:05:25,540 --> 00:05:27,400
‫shake, click select.

69
00:05:27,400 --> 00:05:31,600
‫And for this, we're going to call this BP Depth Camera Shake.

70
00:05:32,320 --> 00:05:38,430
‫Now the death camera shake is going to be a little bit more violent than the hit camera shake.

71
00:05:38,440 --> 00:05:42,460
‫The hit camera shake will shake the camera when our projectile hit something.

72
00:05:42,460 --> 00:05:47,360
‫But the death camera shake is going to shake the camera when something dies.

73
00:05:47,380 --> 00:05:51,940
‫So for the oscillation duration, I'm going to make this a bit longer.

74
00:05:51,940 --> 00:05:57,040
‫I'm going to go 4.3, 5 seconds and four, blend in time and out time.

75
00:05:57,040 --> 00:06:00,070
‫I'm going to set these both to 0.1.

76
00:06:01,000 --> 00:06:03,820
‫Now, just a side note blend in and out time.

77
00:06:03,820 --> 00:06:07,990
‫Are percentages of the full time normalized between zero and one?

78
00:06:07,990 --> 00:06:12,460
‫So point one is 10% of the full oscillation duration.

79
00:06:12,490 --> 00:06:21,430
‫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

80
00:06:21,430 --> 00:06:26,060
‫that we only jerk the camera in X and Y upon -- death.

81
00:06:26,080 --> 00:06:29,130
‫This way we'll get a bit of a different looking camera shake.

82
00:06:29,140 --> 00:06:33,280
‫And for the frequency, I'm going to set these both to 20.

83
00:06:35,440 --> 00:06:41,890
‫So we now have a camera shake and it's time to implement actually playing these camera shakes from the

84
00:06:41,890 --> 00:06:43,810
‫C++ side.

85
00:06:44,470 --> 00:06:49,480
‫Now in order to play a camera shake, we need some camera shake variables.

86
00:06:49,510 --> 00:06:56,140
‫If you're using an older version of Unreal Engine, Unreal Engine 4.25 and below specifically, then

87
00:06:56,140 --> 00:06:58,700
‫the class for your variables is going to be you.

88
00:06:58,720 --> 00:06:59,760
‫Camera shake.

89
00:06:59,770 --> 00:07:03,040
‫But in newer versions 4.2, six and above.

90
00:07:03,040 --> 00:07:05,400
‫And this includes Unreal Engine five.

91
00:07:05,410 --> 00:07:07,330
‫We're going to use you matinee.

92
00:07:07,360 --> 00:07:08,260
‫Camera shake.

93
00:07:08,260 --> 00:07:10,690
‫So that's what we're going to use in this video.

94
00:07:10,990 --> 00:07:14,670
‫Now, the functions to play a camera shake are different as well.

95
00:07:14,680 --> 00:07:19,810
‫If you're on 4.2, five and below, then the function you're going to use is client play.

96
00:07:19,840 --> 00:07:20,800
‫Camera shake.

97
00:07:21,190 --> 00:07:29,080
‫And this is a function on the player controller class now in 4.26 and above, including 5.0, which

98
00:07:29,080 --> 00:07:30,220
‫is what we're using.

99
00:07:30,220 --> 00:07:34,510
‫We're going to use client start camera shake as client play.

100
00:07:34,540 --> 00:07:36,940
‫Camera shake is now deprecated.

101
00:07:37,060 --> 00:07:42,130
‫So since we're using Unreal Engine five, we'll be using clients, start camera shake.

102
00:07:42,130 --> 00:07:47,170
‫And if you're using five, you're going to follow along and use clients start camera shake.

103
00:07:47,170 --> 00:07:54,460
‫But for older engine version, specifically 4.2, five and below, use the class and the function on

104
00:07:54,460 --> 00:08:00,250
‫the left side there and everyone else use the class and function on the right.

105
00:08:00,580 --> 00:08:07,660
‫Now just to show you, here's you camera shake base in the documentation and here is the include for

106
00:08:07,660 --> 00:08:07,780
‫it.

107
00:08:07,780 --> 00:08:14,050
‫So you're going to use this camera slash camera shake base for the include.

108
00:08:14,200 --> 00:08:18,660
‫So first, I'd like to handle the hit camera shake in the projectile class.

109
00:08:18,670 --> 00:08:22,870
‫So here in projectile, I'm going to add a camera shake.

110
00:08:23,110 --> 00:08:25,060
‫Now, this will be forward declared.

111
00:08:25,060 --> 00:08:26,410
‫I'm going to make a U.

112
00:08:26,440 --> 00:08:27,940
‫Camera shake base.

113
00:08:27,940 --> 00:08:29,050
‫It's a pointer.

114
00:08:29,140 --> 00:08:35,350
‫And I'm going to call this hit camera shake now because I'd like to set this from blueprints.

115
00:08:35,350 --> 00:08:38,800
‫Since we have a camera shake blueprint, I'm going to expose this.

116
00:08:38,830 --> 00:08:40,480
‫It's going to be a new property.

117
00:08:40,520 --> 00:08:44,200
‫I'm going to make it edit anywhere and give it a category.

118
00:08:44,830 --> 00:08:48,410
‫And for this, I'll keep it in the combat section.

119
00:08:48,430 --> 00:08:51,670
‫Now I'm ready to play the camera shake.

120
00:08:51,850 --> 00:09:00,100
‫So in projectiles CP, I'm going to place this in on hit here in the check for other actor.

121
00:09:00,100 --> 00:09:05,620
‫And the first thing I'm going to do is make sure that I've set the camera shake from blueprints, which

122
00:09:05,620 --> 00:09:10,540
‫means I need to make sure that hit camera shake is not null.

123
00:09:10,840 --> 00:09:15,220
‫So if I hit camera shake, then I can start the camera shake.

124
00:09:15,960 --> 00:09:23,310
‫And here's a player controller client start camera shake for the versions 4.26 and above.

125
00:09:23,340 --> 00:09:24,990
‫Now notice a couple of things.

126
00:09:25,020 --> 00:09:30,720
‫These involve tw subclass of variables, which means we need a new class.

127
00:09:30,750 --> 00:09:37,950
‫Now we created blueprints for these variables, which means we can easily create a subclass of rather

128
00:09:37,950 --> 00:09:40,190
‫than a regular variable here.

129
00:09:40,200 --> 00:09:49,650
‫So I can take this class you camera shake base and put it inside a PT subclass of so let's say PT subclass

130
00:09:49,650 --> 00:09:56,220
‫of and I'm going to keep the forward declaration here and I don't need the asterisk since PT subclass

131
00:09:56,220 --> 00:10:03,480
‫of just wraps this up in the template and because this hit camera shake is actually a PT subclass of

132
00:10:03,510 --> 00:10:10,170
‫I'm going to call it hit camera shake class and now in projectile that CPP rather than hit camera shake

133
00:10:10,200 --> 00:10:16,350
‫let's call this hit camera shake class and now we can call a client start camera shake.

134
00:10:16,530 --> 00:10:23,100
‫Now this function belongs to the player controller and we're here in projectile CP and we don't have

135
00:10:23,100 --> 00:10:29,670
‫a variable for the player controller, but we have this function get first player controller which exists

136
00:10:29,670 --> 00:10:36,000
‫on the U world class so we can call get world and then call get first player controller.

137
00:10:36,000 --> 00:10:37,470
‫So we're going to do that.

138
00:10:37,470 --> 00:10:45,030
‫So first we'll call Git World and from there we're going to call get first player controller and from

139
00:10:45,030 --> 00:10:52,140
‫get first player controller, we can call a client start camera shake and we'll see that this takes

140
00:10:52,140 --> 00:10:59,610
‫a PT sub class of we're going to pass in hit camera shake class and the rest of these input parameters

141
00:10:59,610 --> 00:11:04,980
‫have default values so we can omit the remaining inputs.

142
00:11:04,980 --> 00:11:07,260
‫So let's go ahead and compile this.

143
00:11:07,860 --> 00:11:11,010
‫So back here in the editor, we're ready to test this out.

144
00:11:11,010 --> 00:11:16,320
‫Now we created the blueprint and the PT sub class of but we need to set that PT sub class of.

145
00:11:16,320 --> 00:11:20,130
‫So let's go into actors and BP projectile.

146
00:11:20,160 --> 00:11:26,160
‫I'm going to open the full blueprint editor and go to the combat section and here's my hit camera shake

147
00:11:26,160 --> 00:11:33,780
‫class t sub class of I can open this and select hit camera shake and now this will be set.

148
00:11:33,780 --> 00:11:39,660
‫So I'm going to compile press play and let's see if we get that camera to shake.

149
00:11:41,140 --> 00:11:42,580
‫And there it goes.

150
00:11:43,300 --> 00:11:44,110
‫Awesome.

151
00:11:44,800 --> 00:11:48,700
‫So next, I want to play a camera shake when the pod dies.

152
00:11:48,700 --> 00:11:54,410
‫So I'm going to go into bass pond and add a camera shake variable here.

153
00:11:54,430 --> 00:11:59,950
‫So down here at the bottom, let's make another t subclass of variable.

154
00:11:59,980 --> 00:12:01,480
‫I'm going to forward declare it.

155
00:12:01,480 --> 00:12:09,490
‫It's going to be you camera shake base and I'm going to call this depth camera shake class.

156
00:12:09,700 --> 00:12:13,720
‫And just like our other one, we're going to make this a U property.

157
00:12:14,290 --> 00:12:24,280
‫Edit Anywhere Category combat and now we have a camera shake class here in base pon.

158
00:12:24,610 --> 00:12:30,550
‫Now I'm going to challenge you to play the death camera shake for the pawn when it dies.

159
00:12:30,550 --> 00:12:35,560
‫So you're going to do this when the -- dies and that's going to be in handle destruction, of course.

160
00:12:35,560 --> 00:12:42,490
‫So choose the correct location in this function to play this camera shake and then compile your code.

161
00:12:42,490 --> 00:12:48,910
‫Set the sub class of value in both the tank and tower blueprint classes and test it out.

162
00:12:48,910 --> 00:12:51,520
‫Pause the video and implement the death camera.

163
00:12:51,520 --> 00:12:52,540
‫Shake now.

164
00:12:55,580 --> 00:12:55,820
‫Okay.

165
00:12:55,820 --> 00:12:58,260
‫So we have our def camera shake class.

166
00:12:58,280 --> 00:13:04,460
‫Let's go into base pond CP and I'm going to scroll up to handle destruction.

167
00:13:04,460 --> 00:13:12,320
‫And the first thing I'm going to do is check to make sure depth camera shake class is set and if it

168
00:13:12,320 --> 00:13:15,980
‫is, then we can actually play the camera shake.

169
00:13:16,040 --> 00:13:21,530
‫Now we don't have a pointer to the player controller here, so I'm going to call Get World from here,

170
00:13:21,920 --> 00:13:27,290
‫get first player controller and from there I'm going to call.

171
00:13:28,370 --> 00:13:30,380
‫Client start camera shake.

172
00:13:31,650 --> 00:13:36,150
‫And in here we can pass in depth camera, shake class.

173
00:13:36,780 --> 00:13:38,070
‫And there we have it.

174
00:13:38,160 --> 00:13:45,300
‫So let's compile this and we'll hop back into the editor and I'm going to open the --'s folder, BP

175
00:13:45,300 --> 00:13:46,190
‫-- tank.

176
00:13:46,200 --> 00:13:48,960
‫And here we have depth camera shake class.

177
00:13:48,990 --> 00:13:50,330
‫I'm going to set this to death.

178
00:13:50,340 --> 00:13:54,060
‫Camera, shake, compile and save and close.

179
00:13:54,090 --> 00:13:56,160
‫I'm going to close the projectile as well.

180
00:13:56,160 --> 00:14:02,880
‫And open BP pond, turret and set depth camera shake class to depth camera shake here as well.

181
00:14:02,910 --> 00:14:04,800
‫Now we can test out death.

182
00:14:04,800 --> 00:14:06,360
‫So let's see how this works.

183
00:14:06,390 --> 00:14:10,470
‫Kay, I'm going to go up to one of the towers and.

184
00:14:11,490 --> 00:14:12,420
‫Boehm.

185
00:14:12,420 --> 00:14:14,220
‫The camera shake works.

186
00:14:14,640 --> 00:14:19,360
‫Now, the last thing to check is if we get the camera shake when the towers die.

187
00:14:19,380 --> 00:14:22,080
‫So let's go ahead and kill one of the towers.

188
00:14:22,810 --> 00:14:23,930
‫And there we go.

189
00:14:23,950 --> 00:14:27,190
‫We got the camera to shake.

190
00:14:27,220 --> 00:14:28,030
‫Awesome.

191
00:14:29,240 --> 00:14:32,480
‫So in summary, we are now shaking the camera.

192
00:14:32,480 --> 00:14:37,760
‫We're shaking it when the projectile hit something and when one of the ponds dies.

193
00:14:37,790 --> 00:14:43,890
‫This is just another one of those nice polish up effects that makes our game look a bit more professional.

194
00:14:43,910 --> 00:14:49,460
‫Speaking of polishing up in our next video, we're going to polish up the game and get it in its final

195
00:14:49,460 --> 00:14:56,450
‫working state so we can wrap up this section and have a complete working game under our belts.

196
00:14:56,480 --> 00:14:57,380
‫I'll see you soon.

