1
00:00:00,000 --> 00:00:05,240
♪♪♪

2
00:00:05,240 --> 00:00:06,990
Zak Parrish: All right, we are back.

3
00:00:06,990 --> 00:00:11,840
We are ready to start building some of the actual gameplay in our game.

4
00:00:11,840 --> 00:00:16,960
We will begin by creating an Enemy Character that we can interact with.

5
00:00:16,960 --> 00:00:22,180
In the Content Browser under C++Classes, open the TwinStickShooter folder.

6
00:00:22,180 --> 00:00:25,030
Here is our BaseCharacter C++ class.

7
00:00:25,030 --> 00:00:27,900
Right-click on the BaseCharacter and 

8
00:00:27,900 --> 00:00:33,960
select Create Blueprint class based on BaseCharacter.

9
00:00:33,960 --> 00:00:38,590
Call this class "EnemyCharacter".

10
00:00:38,590 --> 00:00:41,140
These are such creative names, right?

11
00:00:41,140 --> 00:00:44,690
For Path, select the Blueprints folder.

12
00:00:44,690 --> 00:00:46,390
Click the Create Blueprint Class button.

13
00:00:46,390 --> 00:00:49,640
Wait a second, and it magically appears.

14
00:00:49,640 --> 00:00:52,370
Dock this window at the top and adjust the panels 

15
00:00:52,370 --> 00:00:56,100
so we can see all the different bits and pieces again.

16
00:00:56,100 --> 00:00:59,590
We have some of the same things to do as we did with the Hero Character.

17
00:00:59,590 --> 00:01:01,120
Select the Mesh Component. In the Details panel, 

18
00:01:01,120 --> 00:01:04,900
click the Mesh drop down menu and select SK_Mannequin (Skeletal Mesh).

19
00:01:04,900 --> 00:01:08,820
Place the Skeletal Mesh inside the capsule just like before.

20
00:01:08,820 --> 00:01:13,300
Press E to rotate the mesh 90° so it is facing forward.

21
00:01:13,300 --> 00:01:17,640
Now, I don't want the enemies to be the same color as the hero.

22
00:01:17,640 --> 00:01:21,870
That is going to be be confusing and too much to look at.

23
00:01:21,870 --> 00:01:24,450
Let's figure out how we can change the color.

24
00:01:24,450 --> 00:01:27,390
In the Details panel, Double-click to open the Skeletal Mesh.

25
00:01:27,390 --> 00:01:33,290
This opens the Skeletal Mesh on the Mesh tab in Persona.

26
00:01:33,290 --> 00:01:36,710
We can pan around, and see how awesome this character looks.

27
00:01:36,710 --> 00:01:42,490
He does look pretty cool, but we can also see the materials applied to him.

28
00:01:42,490 --> 00:01:47,920
There are two (2) materials: M_UE4Man_Body and UE4Man_Chest_Logo.

29
00:01:47,920 --> 00:01:54,450
The M_UE4Man_Chest_Logo should be an instance of M_UE4Man_Body.

30
00:01:54,450 --> 00:02:02,440
Double-click to open M_UE4Man_Body in the Material Editor.

31
00:02:02,440 --> 00:02:05,160
There is not that much going on here. 

32
00:02:05,160 --> 00:02:08,600
It is really just blending together a few layered materials.

33
00:02:08,600 --> 00:02:13,170
You have some areas that look like metal, dark grey plastic, and then this beige

34
00:02:13,170 --> 00:02:16,460
plastic which sort of dominates the whole character.

35
00:02:16,460 --> 00:02:22,420
That beige color is a parameter named BodyColor.

36
00:02:22,420 --> 00:02:25,340
If we make a dynamic version of this material and change BodyColor, 

37
00:02:25,340 --> 00:02:30,330
we can thereby change the color of the entire character.

38
00:02:30,330 --> 00:02:33,810
Note the spelling, it is BodyColor without a space.

39
00:02:33,810 --> 00:02:36,380
I am going to select BodyColor inside the Details panel 

40
00:02:36,380 --> 00:02:41,500
and press Ctrl + C to Copy, so I don't have to type the name later.

41
00:02:41,500 --> 00:02:45,630
Go back to EnemyCharacter and go to the Construction Script.

42
00:02:45,630 --> 00:02:52,030
Drag-and-drop the Mesh Component into the script to create a reference to it.

43
00:02:52,030 --> 00:02:53,790
Drag a wire off Mesh.

44
00:02:53,790 --> 00:02:59,750
We need a dynamic version of the material that is applied to Index 0.

45
00:02:59,750 --> 00:03:03,530
How do I know the material is at Index 0? Go to EnemyCharacter. 

46
00:03:03,530 --> 00:03:06,400
In the Mesh Details panel, we have Element 0 and Element 1.

47
00:03:06,400 --> 00:03:09,750
Element 0 is the main material. Element 1 is the chest logo, 

48
00:03:09,750 --> 00:03:16,160
which is just giving us the little UE4 logo you see here.

49
00:03:16,160 --> 00:03:19,500
I can zoom right up on the logo.

50
00:03:19,500 --> 00:03:21,780
Go back to EnemyCharacter.

51
00:03:21,780 --> 00:03:29,810
Drag a wire off Mesh and type "dynamic".

52
00:03:29,810 --> 00:03:32,910
Select Create Material Dynamic Instance.

53
00:03:32,910 --> 00:03:36,660
This is a kind of a do it all at once node. I love this node.

54
00:03:36,660 --> 00:03:40,590
This node is grabbing whatever material found in Element Index 0, 

55
00:03:40,590 --> 00:03:44,450
and it is converting it to a dynamic version

56
00:03:44,450 --> 00:03:48,050
so you can change any parameters found inside of it.

57
00:03:48,050 --> 00:03:53,980
Once it has done that, it reapplies it back to the same Element number.

58
00:03:53,980 --> 00:03:57,090
Connect the Construction Script to the Create Dynamic Material Instance.

59
00:03:57,090 --> 00:04:00,780
Let's set this to a value.

60
00:04:00,780 --> 00:04:03,989
I am not saying we will ever use it, but let's do it anyway.

61
00:04:03,989 --> 00:04:07,740
Right-click the Return Value and select Promote to Variable.

62
00:04:07,740 --> 00:04:10,180
Name this variable "DynaMat".

63
00:04:10,180 --> 00:04:13,610


64
00:04:13,610 --> 00:04:16,420
Drag a wire off the Return Value of the 

65
00:04:16,420 --> 00:04:21,250
Dyna Mat variable, type "set vector" 

66
00:04:21,250 --> 00:04:24,320
and select Set Vector Parameter Value.

67
00:04:24,320 --> 00:04:26,030


68
00:04:26,030 --> 00:04:30,310
This node asks for the Parameter Name you want to talk to.

69
00:04:30,310 --> 00:04:32,610
Remember from earlier, we copied BodyColor.

70
00:04:32,610 --> 00:04:37,650
Press Ctrl + V to Paste BodyColor into Parameter Name.

71
00:04:37,650 --> 00:04:39,690
What color are we going to set it to? Click Value to open the Color Picker.

72
00:04:39,690 --> 00:04:42,880
This is where you decide what color you want your Enemy to be.

73
00:04:42,880 --> 00:04:45,880
Let's choose some shade of red.

74
00:04:45,880 --> 00:04:50,930
Let's choose a bright red. There you go.

75
00:04:50,930 --> 00:04:52,390
It just screams danger.

76
00:04:52,390 --> 00:04:58,410
Go to the Construction Script and click Compile. Go to the Viewport tab.

77
00:04:58,410 --> 00:05:02,280
The character is bright red, which is pretty cool. Go to the Construction Script.

78
00:05:02,280 --> 00:05:07,740
Right-click on the Value pin and select Promote to Variable.

79
00:05:07,740 --> 00:05:15,150
Call this variable "EnemyColor".

80
00:05:15,150 --> 00:05:16,410
Go to the Viewport tab.

81
00:05:16,410 --> 00:05:18,410
In the My Blueprint panel, select EnemyColor.

82
00:05:18,410 --> 00:05:20,300
Click Compile. Go to the Details panel under Default Value, 

83
00:05:20,300 --> 00:05:25,010
Double-click Enemy Color to open the Color Picker, and set this to any shade you want.

84
00:05:25,010 --> 00:05:26,580
Your enemy can be anything.

85
00:05:26,580 --> 00:05:28,720
He could be bright yellow.

86
00:05:28,720 --> 00:05:30,360
Or, he could be orange.

87
00:05:30,360 --> 00:05:33,280
I am going to set him back to red, and we will leave that setting.

88
00:05:33,280 --> 00:05:37,460
I will desaturate the color just a little bit. There we go.

89
00:05:37,460 --> 00:05:39,430
That looks very dangerous. You will notice 

90
00:05:39,430 --> 00:05:42,820
this does not change the color of the logo. That is fine.

91
00:05:42,820 --> 00:05:47,470
We will leave it as a nice little beige logo on his chest.

92
00:05:47,470 --> 00:05:53,870
Now, we have a nice visual differentiation between our Hero and our Enemy.

93
00:05:53,870 --> 00:05:59,050
That should make it easier to tell them apart on the screen, which is great.

94
00:05:59,050 --> 00:06:07,970
With that done, let's set up the AIController that is going to drive this Enemy around.

95
00:06:07,970 --> 00:06:11,100
I am only doing this because we are only about 6 minutes into this video.

96
00:06:11,100 --> 00:06:14,440
It is such a simple concept that I didn't want to put it in 

97
00:06:14,440 --> 00:06:18,030
its own video because it would be very, very short.

98
00:06:18,030 --> 00:06:23,120
Go to the Content Browser and select the Blueprints folder to set this up.

99
00:06:23,120 --> 00:06:28,300
Right-click inside the Blueprints folder and select Blueprint Class.

100
00:06:28,300 --> 00:06:31,200
We want to base this class off AIController, 

101
00:06:31,200 --> 00:06:35,650
which does not appear in our Pick Parent Class list. To find AIController, 

102
00:06:35,650 --> 00:06:45,220
expand All Classes, type and select "AIController".

103
00:06:45,220 --> 00:06:48,190
Click the green Select button.

104
00:06:48,190 --> 00:06:52,790
Name this class EnemyAI.

105
00:06:52,790 --> 00:06:54,320
Double-click to open EnemyAI.

106
00:06:54,320 --> 00:06:57,130
This Blueprint is like any other Blueprint.

107
00:06:57,130 --> 00:07:00,630
It has all of the same panels. I will put back the panels back like they were.

108
00:07:00,630 --> 00:07:01,730
Go to the Event Graph.

109
00:07:01,730 --> 00:07:04,910
The AIController has some components to help it do some things.

110
00:07:04,910 --> 00:07:06,850
It has a TransformComponent.

111
00:07:06,850 --> 00:07:10,820
It has a PathFollowingComponent, which will make use of a Nav Mesh.

112
00:07:10,820 --> 00:07:13,590
It also has an ActionsComp or Actions Component, 

113
00:07:13,590 --> 00:07:17,930
which is going to be used for various AI behaviors.

114
00:07:17,930 --> 00:07:23,389
As I mentioned, this is going to be a very, very simple AIController.

115
00:07:23,389 --> 00:07:30,330
Right-click in the graph, type and select "Custom Event".

116
00:07:30,330 --> 00:07:34,790
Call this event "TrackPlayer".

117
00:07:34,790 --> 00:07:35,960
That is all it is going to do.

118
00:07:35,960 --> 00:07:39,340
You could call the event ChasePlayer, TrackPlayer, HuntPlayer, or whatever.

119
00:07:39,340 --> 00:07:41,190
It is going to do the same thing.

120
00:07:41,190 --> 00:07:44,020
It is going to do a special function. Drag off TrackPlayer, 

121
00:07:44,020 --> 00:07:47,530
type and select "AI Move To".

122
00:07:47,530 --> 00:07:49,780
The AI Move To node takes a Pawn 

123
00:07:49,780 --> 00:07:53,050
and tells it to move toward a destination, or toward a 

124
00:07:53,050 --> 00:07:57,160
Target Actor. Once it gets to a within the acceptance radius, it stops.

125
00:07:57,160 --> 00:07:59,880
The nice thing about the AI Move To node is 

126
00:07:59,880 --> 00:08:02,500
it will keep moving the Pawn toward that target

127
00:08:02,500 --> 00:08:05,100
Actor until it hits the acceptance radius.

128
00:08:05,100 --> 00:08:07,769
This means we don't have to call this AI Move To node very often 

129
00:08:07,769 --> 00:08:12,060
in order to have something chase our player pretty much all the time.

130
00:08:12,060 --> 00:08:14,600
We need to assign the Move To node the Pawn that is being driven,

131
00:08:14,600 --> 00:08:16,610
and we need to assign a Target.

132
00:08:16,610 --> 00:08:19,010
The Pawn that is being driven is easy to assign.

133
00:08:19,010 --> 00:08:23,340
Since this is the AIController, this Controller will be plugged 

134
00:08:23,340 --> 00:08:27,840
into the side of our Enemy Character's head like a cartridge.

135
00:08:27,840 --> 00:08:30,500
That is a metaphor. That is not how it is really going to be. There is no cartridge 

136
00:08:30,500 --> 00:08:32,900
hanging off the side of its head. Go with me.

137
00:08:32,900 --> 00:08:37,530
Right-click in the graph, type and select "Get Controlled Pawn".

138
00:08:37,530 --> 00:08:40,320
The Get Controlled Pawn node is literally a reference to the Pawn 

139
00:08:40,320 --> 00:08:43,110
controlled by this AIController.

140
00:08:43,110 --> 00:08:47,460
 

141
00:08:47,460 --> 00:08:49,190
Next, we need the Target Actor.

142
00:08:49,190 --> 00:08:54,900
Right-click in the graph, type and select "Get Player Character".

143
00:08:54,900 --> 00:08:57,480
There it is. We get the Player Character.

144
00:08:57,480 --> 00:08:59,400
Plug the Return Value into Target Actor. The Player Character becomes the Target Actor.

145
00:08:59,400 --> 00:09:00,770
That is all we need to do.

146
00:09:00,770 --> 00:09:02,550
We just need to use the Get Player Character node.

147
00:09:02,550 --> 00:09:05,610
Now when TrackPlayer is called, the Enemy will just

148
00:09:05,610 --> 00:09:09,200
move toward the Hero until it gets within 5 units.

149
00:09:09,200 --> 00:09:11,550
A value of 5 units is fine; we don't need to change that.

150
00:09:11,550 --> 00:09:14,370
However, we do need to have something that

151
00:09:14,370 --> 00:09:17,370
keeps calling TrackPlayer over and over.

152
00:09:17,370 --> 00:09:20,920
We want something to keep pinging to keep tracking the player

153
00:09:20,920 --> 00:09:22,800
because if the Enemy ever gets within this radius, 

154
00:09:22,800 --> 00:09:25,520
the AI Move To node will stop firing.

155
00:09:25,520 --> 00:09:29,980
The Enemy will never chase the player again if we don't explicitly tell him to.

156
00:09:29,980 --> 00:09:35,790
To do that, we are going to set a timer. Right-click, type and select "Set Timer".

157
00:09:35,790 --> 00:09:40,700
A timer in UE4 is just like a camera timer; there will be a countdown.

158
00:09:40,700 --> 00:09:44,290
At the end of the countdown, the timer will call some function.

159
00:09:44,290 --> 00:09:47,020
Type the name of the function inside Function Name.

160
00:09:47,020 --> 00:09:51,710
Set Function Name to "TrackPlayer".

161
00:09:51,710 --> 00:09:53,500
How often do we want to track it?

162
00:09:53,500 --> 00:09:56,130
Set Time to 1.0 second.

163
00:09:56,130 --> 00:10:00,680
Check the Looping checkbox; it will call TrackPlayer every second.

164
00:10:00,680 --> 00:10:02,320
Notice, Set Timer is not an event.

165
00:10:02,320 --> 00:10:08,470
We need something that will plug into the executable pin and call this node.

166
00:10:08,470 --> 00:10:11,450
Drag the Event BeginPlay node over and plug it into the Set Timer node.

167
00:10:11,450 --> 00:10:16,940
This means the moment this AI character spawns, or the moment the game begins, 

168
00:10:16,940 --> 00:10:19,340
this Set Timer will be called.

169
00:10:19,340 --> 00:10:22,050
Set Timer is going to keep calling TrackPlayer once per second 

170
00:10:22,050 --> 00:10:27,050
and keep telling the AI to chase the Player, over and over.

171
00:10:27,050 --> 00:10:29,600
Click Compile and click Save.

172
00:10:29,600 --> 00:10:33,010
Then, go to the EnemyCharacter tab. We are going to set up a few things.

173
00:10:33,010 --> 00:10:36,480
Click the Class Defaults button.

174
00:10:36,480 --> 00:10:41,500
In the Details panel under Pawn, click the AIController Class property 

175
00:10:41,500 --> 00:10:45,000
drop down menu and select EnemyAI.

176
00:10:45,000 --> 00:10:47,120
Click Compile and click Save.

177
00:10:47,120 --> 00:10:53,680
Now, watch this. Drag-and-drop EnemyCharacter into the world and click Play.

178
00:10:53,680 --> 00:10:55,010
Nothing is going to happen yet.

179
00:10:55,010 --> 00:10:58,800
Let's just move over to the enemy. He is just sitting here being boring.

180
00:10:58,800 --> 00:11:00,340
His behavior is actually there.

181
00:11:00,340 --> 00:11:05,350
He has the requisite logic to make him move around.

182
00:11:05,350 --> 00:11:09,280
He doesn't have a Navigation Mesh yet.

183
00:11:09,280 --> 00:11:11,690
Navigation Meshes are very easy to do in UE4.

184
00:11:11,690 --> 00:11:17,360
Watch this. In the Modes panel, select the Volumes category.

185
00:11:17,360 --> 00:11:20,840
You should see Nav Mesh Bounds Volume.

186
00:11:20,840 --> 00:11:22,520
Drag-and-drop Nav Mesh Bounds Volume onto your floor.

187
00:11:22,520 --> 00:11:27,450
Move the Nav Mesh Bounds Volume down because it needs to penetrate into your floor.

188
00:11:27,450 --> 00:11:29,080
Press R to use the Scale tool and scale 

189
00:11:29,080 --> 00:11:33,550
the volume so it completely covers the floor.

190
00:11:33,550 --> 00:11:36,390
Press the P key to visualize your Nav Mesh.

191
00:11:36,390 --> 00:11:37,570
There you go.

192
00:11:37,570 --> 00:11:40,010
There is your Navigation Mesh. It is already done.

193
00:11:40,010 --> 00:11:44,250
Again, it is very, very easy. Click Play.

194
00:11:44,250 --> 00:11:48,170
Oh my goodness, he is so fast! We can't get away from him!

195
00:11:48,170 --> 00:11:50,200
That is actually kind of ridiculous.

196
00:11:50,200 --> 00:11:51,750
We need to slow him down.

197
00:11:51,750 --> 00:11:53,830
Click Pause to stop playing.

198
00:11:53,830 --> 00:11:56,330
In the Content Browser, Double-click to open the EnemyCharacter.

199
00:11:56,330 --> 00:12:00,960
In the Components panel, select the CharacterMovementComponent.

200
00:12:00,960 --> 00:12:02,330
In the Details panel under Character Movement: Walking, 

201
00:12:02,330 --> 00:12:10,180
set the Max Walk Speed to 200. 

202
00:12:10,180 --> 00:12:12,960
That will probably make the game too easy, but you can always tweak the value later.

203
00:12:12,960 --> 00:12:17,470
Click Compile and click Save. Go to ArenaMap and click Play.

204
00:12:17,470 --> 00:12:19,190
There you go. The enemy is chasing us, 

205
00:12:19,190 --> 00:12:22,579
and he will keep chasing us over and over.

206
00:12:22,579 --> 00:12:24,240
If he touches us, he will wait a second 

207
00:12:24,240 --> 00:12:27,510
and then he will start chasing again.

208
00:12:27,510 --> 00:12:28,570
There you go.

209
00:12:28,570 --> 00:12:31,940
We have an enemy with his own AI that is just 

210
00:12:31,940 --> 00:12:35,160
chasing the Player, which is pretty awesome.

211
00:12:35,160 --> 00:12:37,120
Press Pause.

212
00:12:37,120 --> 00:12:40,240
That is going to wrap things up for this video.

213
00:12:40,240 --> 00:12:40,940
Thanks a lot.

214
00:12:40,940 --> 00:12:49,603
♪♪♪


