﻿1
00:00:04,130 --> 00:00:10,460
‫So the goal for this video is to have projectiles that actually launch through the air and behave as

2
00:00:10,460 --> 00:00:11,930
‫projectiles should.

3
00:00:12,020 --> 00:00:13,520
‫Hey, welcome back.

4
00:00:13,550 --> 00:00:19,430
‫In this video, we're concerned with making our projectile actually behave like a projectile and move.

5
00:00:19,610 --> 00:00:22,040
‫Now, there are different ways to handle this.

6
00:00:22,070 --> 00:00:28,220
‫One way is to manually set the location and rotation of the projectile ourselves.

7
00:00:28,250 --> 00:00:33,680
‫Now, this would generally require us to make the update every frame, so we would probably put this

8
00:00:33,680 --> 00:00:34,940
‫in the tick function.

9
00:00:35,210 --> 00:00:41,810
‫Another way is to simply add an impulse to the projectile and let the physics engine take over.

10
00:00:41,900 --> 00:00:48,440
‫Essentially, we're applying a force and launching that projectile and letting gravity do its thing,

11
00:00:48,440 --> 00:00:51,380
‫and the projectile will just fly off into the air.

12
00:00:51,410 --> 00:00:55,310
‫Now, another way would be to use a movement component.

13
00:00:55,340 --> 00:01:00,560
‫Now, this is a special type of component that we would add to our projectile class.

14
00:01:00,560 --> 00:01:06,230
‫And after setting some parameters on the movement component, the movement component will handle the

15
00:01:06,230 --> 00:01:08,060
‫movement for the actor.

16
00:01:08,090 --> 00:01:15,860
‫Now it just so happens that Unreal Engine has a built in type of component made specifically for projectiles.

17
00:01:15,860 --> 00:01:20,210
‫So this takes advantage of some of the built in features of Unreal Engine.

18
00:01:20,210 --> 00:01:26,120
‫And by doing this, we allow the movement component to handle the movement for us based on the settings

19
00:01:26,120 --> 00:01:27,020
‫that we provide.

20
00:01:27,020 --> 00:01:29,360
‫So this is the method that we're going to use.

21
00:01:29,360 --> 00:01:35,750
‫So we'd like to add a projectile movement component to our projectile class, and this is what will

22
00:01:35,750 --> 00:01:38,690
‫handle the movement for the projectile object.

23
00:01:38,690 --> 00:01:45,440
‫So as we spawn a projectile in the world, the projectile movement component which belongs to the projectile

24
00:01:45,440 --> 00:01:51,620
‫class, can be set up and customized based on the variables on the projectile movement class that we

25
00:01:51,650 --> 00:01:52,190
‫set.

26
00:01:52,220 --> 00:01:58,340
‫Now we're going to set a couple of those, such as its initial speed and its max speed and the projectile

27
00:01:58,340 --> 00:02:02,750
‫movement component will actually move the projectile in the world for us.

28
00:02:02,780 --> 00:02:06,290
‫Now, here's the Unreal Engine Documentation page for you.

29
00:02:06,290 --> 00:02:07,940
‫Projectile movement component.

30
00:02:07,940 --> 00:02:13,130
‫This is the component that we're concerned with and you'll see that it says Projectile Movement Component

31
00:02:13,130 --> 00:02:16,700
‫updates the position of another component during its tick.

32
00:02:16,700 --> 00:02:19,340
‫By default, it's going to move the route component.

33
00:02:19,370 --> 00:02:20,900
‫Now here's the include.

34
00:02:20,900 --> 00:02:26,060
‫And if you continue scrolling down, you'll see some of the variables that can be set on the movement

35
00:02:26,060 --> 00:02:26,810
‫component.

36
00:02:26,810 --> 00:02:30,740
‫So scroll through this and take a look and see what the options are.

37
00:02:30,770 --> 00:02:36,770
‫Now we add a projectile movement component to our class the same way we would add any other component,

38
00:02:36,770 --> 00:02:39,350
‫which means you already know how to do this.

39
00:02:39,350 --> 00:02:45,980
‫So your challenge is to go into the projectile class and add a you projectile movement component pointer

40
00:02:45,980 --> 00:02:49,310
‫variable and expose this by making it visible anywhere.

41
00:02:49,310 --> 00:02:54,140
‫And that way we can easily edit the projectile movement component from within blueprints.

42
00:02:54,150 --> 00:02:59,560
‫Now you're going to construct it in the projectile constructor using create default sub object.

43
00:02:59,570 --> 00:03:05,900
‫Don't forget to include the proper header and set the initial speed and max speed variables of the projectile

44
00:03:05,900 --> 00:03:06,920
‫movement component.

45
00:03:06,920 --> 00:03:12,650
‫Now choose your own values for these and set them in the constructor and then playtest the game.

46
00:03:12,650 --> 00:03:18,530
‫You're going to adjust initial speed and max speed in the details panel by selecting the component in

47
00:03:18,530 --> 00:03:19,790
‫the projectile blueprint.

48
00:03:19,790 --> 00:03:25,910
‫And this will give you a little bit of experience tweaking parameters and experimenting as a developer.

49
00:03:25,910 --> 00:03:30,080
‫So pause the video and create the projectile movement component now.

50
00:03:32,900 --> 00:03:33,180
‫Okay.

51
00:03:33,230 --> 00:03:39,380
‫So I'm here in projectile H and you probably added your component in the private section.

52
00:03:39,380 --> 00:03:41,780
‫So if you did, you have the right instincts.

53
00:03:41,780 --> 00:03:43,730
‫We're going to make this a private variable.

54
00:03:43,730 --> 00:03:44,180
‫That's okay.

55
00:03:44,180 --> 00:03:48,040
‫If you didn't, you can easily move it to the private section if you wish.

56
00:03:48,050 --> 00:03:54,560
‫Now, this will be a U projectile movement component, and that's a pointer.

57
00:03:54,560 --> 00:03:58,610
‫And we can simply call this projectile movement component.

58
00:03:58,760 --> 00:04:05,300
‫Now, I'm going to give this a U property and simply make this visible anywhere.

59
00:04:06,020 --> 00:04:08,210
‫Now, you probably gave it a category.

60
00:04:08,210 --> 00:04:13,130
‫If not, that's totally fine, but I'm going to give it a category and call it movement.

61
00:04:13,130 --> 00:04:15,650
‫So we have the projectile movement component.

62
00:04:15,650 --> 00:04:20,660
‫I'm going to leave off the forward declaration and see if I can get away with compiling now here in

63
00:04:20,660 --> 00:04:24,290
‫projectile CP, I'm going to include the header file.

64
00:04:24,290 --> 00:04:31,340
‫So back to the documentation page, I'm going to copy this include and simply paste it in here in projectile.

65
00:04:31,340 --> 00:04:34,250
‫And now I'm ready to construct my component.

66
00:04:34,250 --> 00:04:42,440
‫So I'm going to say projectile movement component and I'm going to use create default sub object and

67
00:04:42,440 --> 00:04:48,140
‫the type will be you projectile movement component.

68
00:04:48,470 --> 00:04:55,760
‫And for the text, I'm simply going to call this projectile movement component just like that.

69
00:04:55,760 --> 00:04:59,300
‫There's my semicolon and there we have it.

70
00:04:59,330 --> 00:05:07,850
‫Now as instructed we're going to set projectile movement, component max speed, and I'm going to give

71
00:05:07,850 --> 00:05:14,810
‫this an initial speed of, say, 1300 F This is something that we will experiment with and through play

72
00:05:14,810 --> 00:05:17,600
‫testing will adjust this to the right value.

73
00:05:17,600 --> 00:05:25,490
‫Now I'm going to set projectile movement component initial speed, and I'll set it to the same value.

74
00:05:25,910 --> 00:05:31,190
‫So initial speed is going to be how fast the projectile component is when it starts.

75
00:05:31,190 --> 00:05:33,710
‫And of course, it'll never go over max speed.

76
00:05:33,860 --> 00:05:35,750
‫Let's go ahead and compile this.

77
00:05:36,050 --> 00:05:42,200
‫Okay, so I'm getting a compilation error and if I go up I'll see that it's referencing projectile h.

78
00:05:42,350 --> 00:05:47,240
‫So let's go back to projectile H and it says Projectile H 27.

79
00:05:47,240 --> 00:05:51,020
‫It's referring to line 27 and that's this line right here.

80
00:05:51,140 --> 00:05:56,090
‫And we get this projectile movement component is not a member of a projectile.

81
00:05:56,120 --> 00:05:59,990
‫Remember, this was the type of error we saw when we didn't forward declare.

82
00:05:59,990 --> 00:06:06,590
‫So we can easily forward declare this with the class keyword and compile again and we get a successful

83
00:06:06,590 --> 00:06:07,400
‫compile.

84
00:06:07,400 --> 00:06:12,830
‫So again, this is how we can learn whether or not a particular component is included by default.

85
00:06:12,830 --> 00:06:17,270
‫And we saw that this one is not so with a successful compile.

86
00:06:17,270 --> 00:06:18,890
‫Let's hop back in the editor.

87
00:06:19,280 --> 00:06:26,030
‫Okay, so I'm back in the editor and I'm going to go into blueprints and actors and here is BFP projectile.

88
00:06:26,300 --> 00:06:28,190
‫So here NP projectile.

89
00:06:28,190 --> 00:06:32,090
‫Now I see that projectile movement component is here.

90
00:06:32,390 --> 00:06:38,870
‫And in the details panel, you can see under projectile we have initial speed and max speed and you

91
00:06:38,870 --> 00:06:43,280
‫can scroll through and see a lot of other parameters that we can set as well.

92
00:06:43,400 --> 00:06:44,840
‫So let's play test this.

93
00:06:44,840 --> 00:06:49,190
‫I'm going to hit play and left click and check it out.

94
00:06:49,190 --> 00:06:51,200
‫Our projectiles are moving.

95
00:06:51,200 --> 00:06:55,550
‫They are flying through the air and they stop once they actually hit something.

96
00:06:55,550 --> 00:07:00,260
‫Now, eventually what we'd like to do is have them blow up and cause damage.

97
00:07:00,260 --> 00:07:02,780
‫But this is a great starting point.

98
00:07:02,780 --> 00:07:08,420
‫Now let's move within fire range and see if the turrets will spawn a projectile.

99
00:07:08,420 --> 00:07:09,740
‫And of course they don't.

100
00:07:09,740 --> 00:07:13,640
‫And the reason is because we have that TW subclass of variable.

101
00:07:13,640 --> 00:07:19,310
‫So if you're wondering why the turrets weren't actually spawning projectiles, you may not have set

102
00:07:19,310 --> 00:07:19,730
‫that.

103
00:07:19,730 --> 00:07:25,370
‫So let's go ahead and go into ponds and beep pond, turret and open full blueprint.

104
00:07:25,370 --> 00:07:29,960
‫Editor And we placed the projectile class in the combat section.

105
00:07:29,960 --> 00:07:37,790
‫This is our subclass of so if we set this to BP projectile now our turret should start spawning projectiles

106
00:07:37,790 --> 00:07:38,780
‫as well.

107
00:07:38,780 --> 00:07:41,960
‫So let's get in fire range and there we have it.

108
00:07:41,960 --> 00:07:43,910
‫It's shooting projectiles at us.

109
00:07:43,910 --> 00:07:46,550
‫So this is looking awesome.

110
00:07:47,030 --> 00:07:48,950
‫So we now have projectiles.

111
00:07:48,950 --> 00:07:51,230
‫So let's take a look at our section plan.

112
00:07:51,230 --> 00:07:56,900
‫We've already created a tank that can move throughout the world and we're now handling input with the

113
00:07:56,900 --> 00:07:59,150
‫WASD keys and mouse clicks.

114
00:07:59,150 --> 00:08:05,510
‫We've created an enemy turret class, we called it tower in C++ and we've added fire functionality with

115
00:08:05,510 --> 00:08:06,590
‫projectiles.

116
00:08:06,590 --> 00:08:11,240
‫Now next, we need to handle health damage and destruction in this game.

117
00:08:11,240 --> 00:08:15,770
‫So those are our next steps and those are coming up in the videos to come.

118
00:08:15,770 --> 00:08:21,890
‫So now that we've added a projectile movement component, we now have actual projectiles.

119
00:08:21,890 --> 00:08:26,990
‫I'll see you in the next video when we start to talk about how we can make these projectiles actually

120
00:08:26,990 --> 00:08:29,270
‫blow up and cause damage.

121
00:08:29,690 --> 00:08:30,650
‫I'll see you soon.

