WEBVTT 1 00:00:05.749 --> 00:00:10.069 Game in-depth section Navigation system 2 00:00:23.550 --> 00:00:26.050 Hello, this is Younghoon Lee 3 00:00:26.050 --> 00:00:30.679 What we're going to learn today is the Navigation System 4 00:00:30.679 --> 00:00:34.829 In this section, the path finding system of Unreal 5 00:00:34.829 --> 00:00:38.239 the Navigation System, is what we will learn about 6 00:00:38.239 --> 00:00:41.119 And using a Navigation Invoker 7 00:00:41.119 --> 00:00:43.469 we're going to create paths in real-time 8 00:00:43.469 --> 00:00:46.959 and learn about ways to travel towards the destination 9 00:00:46.959 --> 00:00:50.009 Also, using this, we'll learn how to 10 00:00:50.009 --> 00:00:52.439 implement the patrol function 11 00:00:52.584 --> 00:00:56.724 Path finding using the Navigation System 12 00:00:58.239 --> 00:01:02.619 This time, we're going to try processing the Path Finding 13 00:01:02.619 --> 00:01:06.379 Normally, the enemy comes toward the player like this 14 00:01:06.379 --> 00:01:12.339 But what would happen if there's an obstacle in-between? 15 00:01:12.339 --> 00:01:18.879 Let's place a cube and see the results 16 00:01:18.879 --> 00:01:24.479 Make an obstacle like this and execute 17 00:01:24.479 --> 00:01:28.839 Then the enemy can't come towards the player 18 00:01:28.839 --> 00:01:32.939 That's because the enemy is going straight forward 19 00:01:32.939 --> 00:01:37.239 To go towards the direction of the player 20 00:01:37.239 --> 00:01:40.519 The direction is set like this 21 00:01:40.519 --> 00:01:43.309 Through AddMovementInput 22 00:01:43.309 --> 00:01:45.499 it continues to go in that direction 23 00:01:45.499 --> 00:01:48.259 But in that direction, if there's an obstacle 24 00:01:48.259 --> 00:01:51.800 then it can't move properly 25 00:01:51.800 --> 00:01:55.700 So in engines like Unreal 26 00:01:55.700 --> 00:01:57.400 to process these 27 00:01:57.400 --> 00:01:59.360 they provide a Path Finding System 28 00:01:59.360 --> 00:02:01.360 Usually, in English 29 00:02:01.360 --> 00:02:08.180 they call it Path Finding 30 00:02:08.180 --> 00:02:09.180 They call it like this 31 00:02:09.180 --> 00:02:15.039 In other words, it's called Navigation 32 00:02:15.039 --> 00:02:16.759 Like this 33 00:02:16.759 --> 00:02:20.679 Then using the Navigation System of Unreal 34 00:02:20.679 --> 00:02:24.759 we're going to produce this 35 00:02:24.759 --> 00:02:28.909 Normally, for Navigation and Path Finding 36 00:02:28.909 --> 00:02:34.039 there's the most famous algorithm 37 00:02:34.039 --> 00:02:37.759 There's something called A* algorithm among the algorithms 38 00:02:37.759 --> 00:02:41.759 Basically, when there's a surface like this 39 00:02:41.759 --> 00:02:45.099 it's the concept of the finding the shortest path 40 00:02:45.099 --> 00:02:46.699 For example, like this 41 00:02:46.699 --> 00:02:50.479 if they're arranged like this 42 00:02:52.079 --> 00:02:54.679 For example, you want to move quickly from here to here 43 00:02:54.679 --> 00:02:57.299 Then let's say that there's an obstacle here 44 00:02:57.299 --> 00:03:00.759 Then for example, let's say that there are obstacles like this 45 00:03:00.759 --> 00:03:04.609 Then normally, going this way is the fastest 46 00:03:04.609 --> 00:03:07.759 but you would end up traveling like this 47 00:03:07.759 --> 00:03:09.279 The most complicated it gets 48 00:03:09.279 --> 00:03:12.759 the more calculation it performs 49 00:03:12.759 --> 00:03:16.599 Basically, this A* algorithm is used 50 00:03:16.599 --> 00:03:18.759 for Path Finding 51 00:03:18.759 --> 00:03:21.189 Actually, A* algorithm not only can do 52 00:03:21.189 --> 00:03:22.759 these rectangular forms 53 00:03:22.759 --> 00:03:25.659 but it can also do triangles 54 00:03:25.659 --> 00:03:29.299 It can use triangles that look like these 55 00:03:29.299 --> 00:03:32.979 Or pentagons, hexagons, or octagons 56 00:03:32.979 --> 00:03:35.759 These can also be used 57 00:03:35.759 --> 00:03:40.279 So the side adjacent to the current side 58 00:03:40.279 --> 00:03:42.829 Finding the shortest path toward that side 59 00:03:42.829 --> 00:03:47.419 is what this formula does 60 00:03:47.439 --> 00:03:50.239 It's implemented like this in Unreal as well 61 00:03:50.239 --> 00:03:53.419 Then to process these, basically 62 00:03:53.419 --> 00:03:55.619 certain data has to be made 63 00:03:55.619 --> 00:03:58.359 So to put this in more simple terms 64 00:03:58.359 --> 00:04:00.299 we need to make paths 65 00:04:00.299 --> 00:04:02.759 We can travel only if there are paths 66 00:04:02.759 --> 00:04:08.139 Then in Unreal, to carry out this Path Finding 67 00:04:08.139 --> 00:04:11.219 we need two main elements 68 00:04:11.219 --> 00:04:13.669 One of them is path 69 00:04:13.669 --> 00:04:16.359 We need paths, that's how we can travel 70 00:04:16.359 --> 00:04:20.409 Second, we need the subject that actually travels there 71 00:04:20.409 --> 00:04:29.500 The controller that finds the path 72 00:04:29.500 --> 00:04:32.200 In a way, Path Finding is A.I. 73 00:04:32.200 --> 00:04:35.140 We can call it A.I. 74 00:04:35.140 --> 00:04:38.040 It's basically an A.I. 75 00:04:38.040 --> 00:04:40.600 The thing that process, that corresponds to the A.I. is 76 00:04:40.600 --> 00:04:43.360 the controller that finds the path 77 00:04:43.360 --> 00:04:50.760 Here, it's called AIController 78 00:04:50.760 --> 00:04:52.510 That's how we can call it 79 00:04:52.510 --> 00:04:57.760 So first, we need to make the path and the controller 80 00:04:57.760 --> 00:05:01.760 Basically, to make the path 81 00:05:01.760 --> 00:05:05.060 if you look here, in Place Actors 82 00:05:05.060 --> 00:05:07.300 there's a part called Volumes 83 00:05:07.300 --> 00:05:13.210 Go to Volumes 84 00:05:13.210 --> 00:05:16.320 and there's something called Nav Mesh Bounds Volume 85 00:05:16.320 --> 00:05:18.460 Take this out 86 00:05:18.460 --> 00:05:21.240 This is the volume that creates the path 87 00:05:21.240 --> 00:05:24.980 It can create an area 88 00:05:24.980 --> 00:05:28.250 We'll try using this 89 00:05:28.250 --> 00:05:32.520 Then if you look at the Volume 90 00:05:32.520 --> 00:05:36.480 you can set its size 91 00:05:36.480 --> 00:05:39.180 First, place it in the center 92 00:05:39.180 --> 00:05:45.940 Now we can widen the size 93 00:05:45.940 --> 00:05:48.940 If you look here, there's Brush Settings 94 00:05:48.940 --> 00:05:50.840 You can use this 95 00:05:50.840 --> 00:05:53.220 Or you can use Scale 96 00:05:53.220 --> 00:05:55.720 You can adjust either of them 97 00:05:55.720 --> 00:05:58.320 I'll use Brush Settings 98 00:05:58.320 --> 00:06:00.570 Select this 99 00:06:00.570 --> 00:06:03.740 Adequately.. should we put it at 2000? 100 00:06:03.740 --> 00:06:05.760 Then it's about this much 101 00:06:05.760 --> 00:06:07.210 Then I think it should be bigger 102 00:06:07.210 --> 00:06:14.700 Let's see... about 4 times bigger? Should we put it at 8000? 103 00:06:14.700 --> 00:06:19.760 Then it's about this much. And for Y as well, 8000 104 00:06:19.760 --> 00:06:25.760 Then it fills up entirely 105 00:06:25.760 --> 00:06:28.440 We don't need to adjust Z necessarily 106 00:06:28.440 --> 00:06:32.860 At this point, in order to see where the actual path is, to see the volume 107 00:06:32.860 --> 00:06:34.710 Without pressing anything 108 00:06:34.710 --> 00:06:36.970 Select the Viewport 109 00:06:36.970 --> 00:06:40.760 And press the P key on the keyboard 110 00:06:40.760 --> 00:06:43.160 Press P, and the area appears like this 111 00:06:43.160 --> 00:06:46.760 This now becomes the path 112 00:06:46.760 --> 00:06:49.810 Then since this is the path, on top of this path 113 00:06:49.810 --> 00:06:53.250 The A.I., the enemy, on top of this path 114 00:06:53.250 --> 00:06:55.620 should be made to travel around the obstacle, this way 115 00:06:55.620 --> 00:06:58.380 Should we arrange the obstacle to be a little longer? 116 00:06:58.380 --> 00:07:02.200 I'll widen it a little 117 00:07:02.200 --> 00:07:07.080 Arrange it like this, and we're going to make it find the path 118 00:07:07.080 --> 00:07:11.630 This time, let's take a look at the enemy 119 00:07:11.630 --> 00:07:17.240 Select the enemy, and in its details 120 00:07:17.240 --> 00:07:21.190 Go all the way down, and there's a part called Pawn 121 00:07:21.190 --> 00:07:25.400 If you look at the Pawn 122 00:07:25.400 --> 00:07:30.700 it's set like this, right? 123 00:07:30.700 --> 00:07:33.990 In AI Controller Class, AIController 124 00:07:33.990 --> 00:07:36.300 is selected, right? 125 00:07:36.300 --> 00:07:39.950 Auto Possess AI is set as Placed in World 126 00:07:39.950 --> 00:07:41.700 If it's set like this, what happens is 127 00:07:41.700 --> 00:07:45.740 Normally, the controller of this guy is AIController 128 00:07:45.740 --> 00:07:50.640 Everyone, Unreal is basically this kind of concept 129 00:07:50.640 --> 00:07:54.580 The game board, or the world is there 130 00:07:54.580 --> 00:07:57.080 And there are characters on this world 131 00:07:57.080 --> 00:07:59.100 Pawns or characters 132 00:07:59.100 --> 00:08:01.900 Then the user, out of the pawns here 133 00:08:01.900 --> 00:08:05.650 decides which one to get hold of and move 134 00:08:05.650 --> 00:08:07.250 That's what they're controlling 135 00:08:07.250 --> 00:08:16.860 So normally, there's the Player Controller 136 00:08:16.860 --> 00:08:19.310 and then 137 00:08:19.310 --> 00:08:22.360 This one receives input, and with the input value 138 00:08:22.360 --> 00:08:24.440 there's the concept of being able to control it 139 00:08:24.440 --> 00:08:26.840 Other than this, Path Finding 140 00:08:26.840 --> 00:08:34.440 has a separate AIController 141 00:08:34.440 --> 00:08:39.040 So for AI too, it gets hold of this guy 142 00:08:39.040 --> 00:08:40.690 It's the concept of possessing 143 00:08:40.690 --> 00:08:42.090 The player is possessing this 144 00:08:42.090 --> 00:08:43.840 And this is possessed by the AI 145 00:08:43.840 --> 00:08:47.380 That's the concept you should understand it as 146 00:08:47.380 --> 00:08:50.260 Then basically, this guy is set up like this. And also 147 00:08:50.260 --> 00:08:54.010 What this Auto Possess AI is, is if you expand this part 148 00:08:54.010 --> 00:08:57.230 There are two types. Spawned and Placed in World 149 00:08:57.230 --> 00:08:59.760 It can do both of them 150 00:08:59.760 --> 00:09:05.160 What this means, is that when this character is arranged on level 151 00:09:05.160 --> 00:09:07.710 we can place it static 152 00:09:07.710 --> 00:09:10.220 We can arrange like this through drag and drop 153 00:09:10.220 --> 00:09:14.520 But instead of that, Spawn Actor can be used 154 00:09:14.520 --> 00:09:16.620 to arrange this on level 155 00:09:16.620 --> 00:09:19.000 Which means we can spawn it 156 00:09:19.000 --> 00:09:22.600 Then when we spawn it, this controller 157 00:09:22.600 --> 00:09:27.680 needs to be decided on how to possess it 158 00:09:27.680 --> 00:09:30.490 So when you look here, it looks like this 159 00:09:30.490 --> 00:09:32.890 If it's like this, for example, and then 160 00:09:32.890 --> 00:09:35.320 let's say that you made a creator that creates the enemy 161 00:09:35.320 --> 00:09:39.170 Then that guy doesn't get possessed by the AIController 162 00:09:39.170 --> 00:09:42.870 That's because only for the ones placed in world 163 00:09:42.870 --> 00:09:45.170 the controller automatically 164 00:09:45.170 --> 00:09:48.280 possess them, that's the concept 165 00:09:48.280 --> 00:09:50.430 So this has to be changed like this 166 00:09:50.430 --> 00:09:53.530 Later, if you set the enemy to be created 167 00:09:53.530 --> 00:09:57.730 then when the enemy is spawned, the AI Controller automatically 168 00:09:57.730 --> 00:10:00.760 possesses the enemy from the start 169 00:10:00.760 --> 00:10:05.220 That's how you should configure it 170 00:10:05.220 --> 00:10:08.570 But we're not going to make the enemy creator 171 00:10:08.570 --> 00:10:10.770 We're only going to deal with one, so actually this one 172 00:10:10.770 --> 00:10:13.370 doesn't really make a difference, but as you work more 173 00:10:13.370 --> 00:10:16.080 you may experience trouble due to this 174 00:10:16.080 --> 00:10:18.760 That's why I touched upon it 175 00:10:18.760 --> 00:10:24.120 You should normally set it to this setting 176 00:10:24.120 --> 00:10:27.360 Save it 177 00:10:27.360 --> 00:10:30.760 Then we're going to move the enemy 178 00:10:30.760 --> 00:10:35.360 We'll have to process that in Move 179 00:10:35.360 --> 00:10:39.210 But I told you that there are two conditions 180 00:10:39.210 --> 00:10:42.180 One is path. The path is already created with Volume 181 00:10:42.180 --> 00:10:46.040 Second one needs to be proceeded using the AIController 182 00:10:46.040 --> 00:10:50.170 So if you look in EnemyFSM 183 00:10:50.170 --> 00:10:52.800 we don't have an AIController 184 00:10:52.800 --> 00:10:56.500 So here, in order to have an AIController 185 00:10:56.500 --> 00:10:58.060 we'll make a variable 186 00:10:58.060 --> 00:11:02.760 It's called UPROPERTY 187 00:11:02.760 --> 00:11:07.760 class AAIController 188 00:11:07.760 --> 00:11:10.710 Controllers begin with A 189 00:11:10.710 --> 00:11:12.760 They're in the form of actors 190 00:11:12.760 --> 00:11:15.760 Same thing with player controllers, they start with A 191 00:11:15.760 --> 00:11:23.140 Then, we'll put AI 192 00:11:23.140 --> 00:11:25.760 Then we should fill in this value 193 00:11:25.760 --> 00:11:31.760 We'll fill it in BeginPlay 194 00:11:31.760 --> 00:11:36.780 Here, AI will be in Me because Me possesses it 195 00:11:36.780 --> 00:11:42.020 In Me, do GetController, and you'll be able to bring it 196 00:11:42.020 --> 00:11:44.760 We'll have to cast it to use it 197 00:11:44.760 --> 00:11:50.760 Put Cast 198 00:11:50.760 --> 00:11:59.400 Here, it will be AAIController 199 00:11:59.400 --> 00:12:01.550 Then since we now brought it 200 00:12:01.550 --> 00:12:03.760 we'll take this and move it 201 00:12:03.760 --> 00:12:11.760 Go to TickMove, and we're going to move it using AI 202 00:12:11.760 --> 00:12:16.760 Here, put Me, and AddMovementInput as comment 203 00:12:16.760 --> 00:12:19.760 Then we'll move with the AI 204 00:12:19.760 --> 00:12:23.260 In AI, type Move 205 00:12:23.260 --> 00:12:25.660 and there's MoveTo or MoveToActor, Location, etc 206 00:12:25.660 --> 00:12:29.560 These are here for you to use 207 00:12:29.560 --> 00:12:37.760 From here, I'll use MoveToLocation 208 00:12:37.760 --> 00:12:44.760 This function makes you insert the destination 209 00:12:44.760 --> 00:12:46.130 And it's like this 210 00:12:46.130 --> 00:12:48.760 Since it's difficult to view 211 00:12:48.760 --> 00:12:51.760 we'll take a quick look in the blueprint 212 00:12:51.760 --> 00:12:55.760 Here, put AI MoveTo 213 00:12:55.760 --> 00:12:59.760 and these pop up 214 00:12:59.760 --> 00:13:05.760 If you look here, if you put location into the destination 215 00:13:05.760 --> 00:13:08.460 or put the Target Actor that corresponds to that destination 216 00:13:08.460 --> 00:13:10.060 it can move to that area 217 00:13:10.060 --> 00:13:14.430 And for this Acceptance Radius 218 00:13:14.430 --> 00:13:17.980 it's a range value that indicates, if you reached near that area 219 00:13:17.980 --> 00:13:20.040 then you've arrived 220 00:13:20.040 --> 00:13:23.060 So for example 221 00:13:23.060 --> 00:13:25.350 exactly in that position, that location 222 00:13:25.350 --> 00:13:27.740 needs to be matched in order to arrive 223 00:13:27.740 --> 00:13:30.380 But that's difficult to calculate exactly 224 00:13:30.380 --> 00:13:32.760 That's why we give it a range 225 00:13:32.760 --> 00:13:36.760 Right now, it's set as 5 cm, but that's a little difficult 226 00:13:36.760 --> 00:13:41.620 So you can set this to like 50 cm or something 227 00:13:41.620 --> 00:13:44.300 This, you guys, according to the concept 228 00:13:44.300 --> 00:13:46.020 you can input an appropriate value 229 00:13:46.020 --> 00:13:48.980 So when you arrive, from here 230 00:13:48.980 --> 00:13:51.760 these kinds of signals appear 231 00:13:51.760 --> 00:13:57.920 So similar to this, you need to fill in values here 232 00:13:57.920 --> 00:14:02.980 If you look here, there's Dest., or the Destination 233 00:14:02.980 --> 00:14:05.880 There's the destination, and same thing here 234 00:14:05.880 --> 00:14:08.720 there's the AcceptanceRadius 235 00:14:08.720 --> 00:14:11.640 And similarly, StopOnOverlap 236 00:14:11.640 --> 00:14:13.880 Right? So that's how it's like 237 00:14:13.880 --> 00:14:15.610 Here, what you need to fill in is 238 00:14:15.610 --> 00:14:18.760 The most important part is this, Destination 239 00:14:18.760 --> 00:14:21.760 The Destination is actually the Target's GetActorLocation 240 00:14:21.760 --> 00:14:23.380 That's the Destination 241 00:14:23.380 --> 00:14:29.960 So we'll keep it for now as FVector 242 00:14:29.960 --> 00:14:34.560 We'll set it as destination and keep it 243 00:14:34.560 --> 00:14:38.760 Then change the direction like this 244 00:14:38.760 --> 00:14:44.760 And then we'll insert the destination into here 245 00:14:44.760 --> 00:14:47.410 And to make it arrive at the approximate location 246 00:14:47.410 --> 00:14:51.160 we can put, for example, like 50 247 00:14:51.160 --> 00:14:54.610 But in order to use this 248 00:14:54.610 --> 00:14:56.520 you can't use it as is 249 00:14:56.520 --> 00:14:58.760 You have to add a module 250 00:14:58.760 --> 00:15:02.600 So from here, go to the Build.cs file 251 00:15:02.600 --> 00:15:04.760 Remember? Where you add the module 252 00:15:04.760 --> 00:15:07.760 We're going to add it here 253 00:15:07.760 --> 00:15:09.960 We're going to add two 254 00:15:09.960 --> 00:15:13.110 But it will be good to take a look at this too 255 00:15:13.110 --> 00:15:16.440 Then since it's AI Controller 256 00:15:16.440 --> 00:15:22.380 Should we search it up? 257 00:15:22.380 --> 00:15:27.580 If you look at AIController 258 00:15:27.580 --> 00:15:31.940 You need to use AIModule for it 259 00:15:31.940 --> 00:15:34.420 So this module 260 00:15:34.420 --> 00:15:36.760 will be added here like this 261 00:15:36.760 --> 00:15:38.591 It's AIModule 262 00:15:52.120 --> 00:15:56.020 And while we're on it, we'll add another one 263 00:15:56.020 --> 00:15:58.260 Here, there's AIModule 264 00:15:58.260 --> 00:16:03.880 but when we do Path Finding 265 00:16:04.530 --> 00:16:09.060 there's something called UNavigationSystemV1 266 00:16:09.060 --> 00:16:10.760 We're going to use this class 267 00:16:10.760 --> 00:16:13.760 We'll add the module beforehand as well 268 00:16:13.760 --> 00:16:18.410 If you look here, the module here is NavigationSystem 269 00:16:18.410 --> 00:16:24.120 We'll write this as-is on here 270 00:16:24.120 --> 00:16:27.520 So AIModule and NavigationSystem 271 00:16:27.520 --> 00:16:31.400 are the two modules that we'll add 272 00:16:31.400 --> 00:16:33.140 And we'll come back to here 273 00:16:33.140 --> 00:16:35.200 Here, we're going to use this 274 00:16:35.200 --> 00:16:37.140 We'll have to add headers 275 00:16:37.140 --> 00:16:38.740 For header, like this 276 00:16:38.740 --> 00:16:46.760 Add a header called AIController 277 00:16:46.760 --> 00:16:53.760 If you look here, you need to add it like this 278 00:16:53.760 --> 00:16:56.400 Like this 279 00:16:56.400 --> 00:17:01.760 Add it like this 280 00:17:01.760 --> 00:17:06.980 And since we made it here, let's try executing 281 00:17:06.980 --> 00:17:08.760 If it actually goes 282 00:17:08.760 --> 00:17:11.480 Close Unreal for now 283 00:17:11.480 --> 00:17:15.760 We'll delete this because we don't need it 284 00:17:15.760 --> 00:17:17.360 Close it for now 285 00:17:17.360 --> 00:17:19.951 We'll try building it here 286 00:17:36.520 --> 00:17:38.934 Execute it again 287 00:17:51.280 --> 00:17:55.180 Then the enemy diverts from the obstacle 288 00:17:55.180 --> 00:17:57.760 and comes toward the player like this 289 00:17:57.760 --> 00:18:05.040 If I run away, it follows well like this 290 00:18:05.040 --> 00:18:07.490 This is the basic 291 00:18:07.490 --> 00:18:09.760 Path Finding System that's provided 292 00:18:09.760 --> 00:18:12.060 So the core point is to create the path 293 00:18:12.060 --> 00:18:15.760 and move by using the AIController 294 00:18:15.760 --> 00:18:17.760 It's finding the path 295 00:18:17.760 --> 00:18:20.760 Path Finding is ultimately heading towards the destination 296 00:18:20.760 --> 00:18:24.617 That's the concept of destination that you should put in 297 00:18:26.759 --> 00:18:30.579 Path Finding and the Patrol Function using the Navigation Invoker 298 00:18:31.340 --> 00:18:38.980 Then using this function, we do Path Finding 299 00:18:38.980 --> 00:18:41.020 We're going to make this kind of concept 300 00:18:44.500 --> 00:18:49.760 If you take a look, there's the overall path like this 301 00:18:49.760 --> 00:18:53.760 And there's the enemy standing here 302 00:18:53.760 --> 00:18:55.760 But the player is here 303 00:18:55.760 --> 00:19:01.500 So there's the distance at which the enemy can sense the player 304 00:19:01.500 --> 00:19:04.760 And if it can't sense anything 305 00:19:04.760 --> 00:19:07.970 then it marks a temporary point 306 00:19:07.970 --> 00:19:09.900 and travels to that area 307 00:19:09.900 --> 00:19:15.760 Here, it searches again and goes to another area 308 00:19:15.760 --> 00:19:18.940 While it moves about randomly 309 00:19:18.940 --> 00:19:24.660 if, within the sensing area of the enemy 310 00:19:24.660 --> 00:19:28.560 the player comes in like this 311 00:19:28.560 --> 00:19:33.510 The player comes in like this 312 00:19:33.510 --> 00:19:34.500 Like this 313 00:19:34.500 --> 00:19:38.420 Then instead of going to the place it was headed 314 00:19:38.420 --> 00:19:42.340 the enemy comes toward the player 315 00:19:42.340 --> 00:19:44.760 And if the player runs away again 316 00:19:44.760 --> 00:19:47.500 it runs away to a far area 317 00:19:47.500 --> 00:19:49.180 If it goes beyond a certain distance 318 00:19:49.180 --> 00:19:54.220 the enemy continues to patrol in its original area 319 00:19:54.220 --> 00:19:58.620 So the concept of patrolling 320 00:19:58.620 --> 00:20:01.420 and the concept of tracking, is what we want to make 321 00:20:01.420 --> 00:20:04.980 There are various ways to make these 322 00:20:04.980 --> 00:20:06.160 We can make a state 323 00:20:06.160 --> 00:20:09.460 Patrol or track during the moving state 324 00:20:09.460 --> 00:20:11.080 We can process it like that 325 00:20:11.080 --> 00:20:12.760 There are various ways 326 00:20:12.760 --> 00:20:16.260 In Unreal, ways to process path 327 00:20:16.260 --> 00:20:21.760 exist in many kinds, and among them, there's something called Invoker 328 00:20:21.760 --> 00:20:25.760 Invoker is this kind of concept 329 00:20:25.760 --> 00:20:29.420 Path is something made in a static way 330 00:20:29.420 --> 00:20:31.760 at first. What it means is that 331 00:20:31.760 --> 00:20:34.760 Let's say that there's a big path 332 00:20:34.760 --> 00:20:37.060 We made a very big map 333 00:20:37.060 --> 00:20:39.260 and we made the path information there 334 00:20:39.260 --> 00:20:40.960 Then creating the path information at first 335 00:20:40.960 --> 00:20:42.760 will take a long time 336 00:20:42.760 --> 00:20:46.760 So when it's all made, then on top of the path 337 00:20:46.760 --> 00:20:49.910 the AI is there, and it moves about 338 00:20:49.910 --> 00:20:55.760 That's the concept. But if it's an open world 339 00:20:55.760 --> 00:20:57.760 it will be a problem 340 00:20:57.760 --> 00:21:01.760 Because this map will be huge 341 00:21:01.760 --> 00:21:06.760 Then every time the level of the open world is adjusted 342 00:21:06.760 --> 00:21:08.760 the path has to be re-created 343 00:21:08.760 --> 00:21:10.760 In order to carry out those things 344 00:21:10.760 --> 00:21:13.760 there may be lags 345 00:21:13.760 --> 00:21:16.380 or functional issues may arise 346 00:21:16.380 --> 00:21:18.030 So there's this concept 347 00:21:18.030 --> 00:21:20.060 What this Invoker is, is that 348 00:21:20.060 --> 00:21:23.760 For the overall path 349 00:21:23.760 --> 00:21:26.760 there may be the static concept 350 00:21:26.760 --> 00:21:28.760 and there's also the dynamic concept 351 00:21:28.760 --> 00:21:31.760 Static means everything is already set 352 00:21:31.760 --> 00:21:33.760 They're made ahead of time 353 00:21:38.440 --> 00:21:39.760 That's what it means 354 00:21:39.760 --> 00:21:42.760 Dynamic means that it's made in real-time 355 00:21:45.760 --> 00:21:46.940 Right? 356 00:21:46.940 --> 00:21:48.760 So if Invoker is used like this 357 00:21:48.760 --> 00:21:51.760 the path can be made and processed in real-time 358 00:21:51.760 --> 00:21:55.960 Then what happens when the path is made in Invoker, is that 359 00:21:55.960 --> 00:21:58.760 there's the new area that it will search 360 00:21:58.760 --> 00:22:00.760 Then it will move like this 361 00:22:00.760 --> 00:22:03.120 Then there's the existing path like this, right? 362 00:22:03.120 --> 00:22:05.760 Then it will make a brand new path 363 00:22:05.760 --> 00:22:08.760 Then the existing path is out of the boundary 364 00:22:08.760 --> 00:22:11.520 Then it will delete this 365 00:22:11.520 --> 00:22:13.760 So it dynamically continues making 366 00:22:13.760 --> 00:22:17.400 The concept is to recognize the area around them as paths 367 00:22:17.400 --> 00:22:20.260 So if it's far away, it's not on top of the path 368 00:22:20.260 --> 00:22:22.760 It recognizes it as outside of its recognition range 369 00:22:22.760 --> 00:22:24.760 So it's not a path 370 00:22:24.760 --> 00:22:28.760 Using this, patrolling and tracking can be done 371 00:22:28.760 --> 00:22:31.760 It can carry this out by measuring the distance as well 372 00:22:31.760 --> 00:22:33.060 but we use Invokers like this 373 00:22:33.060 --> 00:22:34.760 We call it the NavigationInvoker 374 00:22:34.760 --> 00:22:37.760 We can use this to make these 375 00:22:37.760 --> 00:22:41.760 So that's what we'll learn today 376 00:22:42.760 --> 00:22:46.640 To process this, we're going to register an Invoker 377 00:22:46.640 --> 00:22:48.640 First let's go to the enemy 378 00:22:48.640 --> 00:22:52.140 On the enemy, we're going to add a component 379 00:22:52.140 --> 00:22:56.580 Type Invoker 380 00:22:56.580 --> 00:23:01.520 There's the NavigationInvoker 381 00:23:01.520 --> 00:23:04.560 You can add it like this, but later 382 00:23:04.560 --> 00:23:06.520 when you make a new enemy 383 00:23:06.520 --> 00:23:08.280 then this isn't there, right? 384 00:23:08.280 --> 00:23:13.430 So we'll create this as a code and add it 385 00:23:13.430 --> 00:23:18.240 If you look here in Navigation, there's Generation Radius 386 00:23:18.240 --> 00:23:20.200 and the Removal Radius 387 00:23:20.200 --> 00:23:21.120 This is what that is 388 00:23:21.120 --> 00:23:23.760 This is the area of newly made path 389 00:23:23.760 --> 00:23:26.760 And after moving and getting far 390 00:23:26.760 --> 00:23:28.760 if it's this much further away 391 00:23:28.760 --> 00:23:31.760 delete the existing area 392 00:23:31.760 --> 00:23:33.760 That's the concept 393 00:23:39.600 --> 00:23:44.760 So I'll set this to about 500 and 800 394 00:23:44.760 --> 00:23:47.760 I'll arrange it like this, then continue working 395 00:23:47.760 --> 00:23:51.540 Then I'll first write this as a code 396 00:23:51.540 --> 00:23:54.140 then continue working on it 397 00:23:54.140 --> 00:23:57.760 Go to the header file of the enemy 398 00:23:57.760 --> 00:23:59.760 I'll make it here 399 00:24:02.410 --> 00:24:06.600 So UPROPERTY 400 00:24:06.600 --> 00:24:09.160 Put EditAnywhere 401 00:24:09.160 --> 00:24:18.460 class UNavigationInvokerComponent 402 00:24:18.460 --> 00:24:20.340 Like this 403 00:24:20.340 --> 00:24:25.760 We'll put NavInvoker here 404 00:24:25.760 --> 00:24:27.760 Should we put Comp? 405 00:24:31.760 --> 00:24:33.760 We'll create this 406 00:24:33.760 --> 00:24:37.060 Then go to the creator of enemy 407 00:24:37.060 --> 00:24:38.760 Right here. Underneath here 408 00:24:38.760 --> 00:24:40.760 we'll continue writing 409 00:24:40.760 --> 00:24:44.760 If you look at the Invoker, there's a dotted line 410 00:24:44.760 --> 00:24:46.760 There's a solid line 411 00:24:46.760 --> 00:24:47.760 It's under the line, right? 412 00:24:47.760 --> 00:24:50.760 Things under here are Actor Components 413 00:24:50.760 --> 00:24:53.040 The ones on top are Scene Components 414 00:24:53.040 --> 00:24:54.360 That's how it is 415 00:24:54.360 --> 00:24:58.760 Since it's underneath, we don't need to attach it 416 00:24:58.760 --> 00:25:01.750 So we'll create it here 417 00:25:01.750 --> 00:25:05.910 Put CreateDefaultSubobject 418 00:25:05.910 --> 00:25:11.360 Here, put UNavigationInvokerComponent 419 00:25:11.360 --> 00:25:13.760 Name it 420 00:25:21.640 --> 00:25:24.760 And we'll need to insert a value here, right? 421 00:25:24.760 --> 00:25:26.260 Earlier, over here 422 00:25:26.260 --> 00:25:29.240 for Generation Radius and Removal Radius 423 00:25:29.240 --> 00:25:31.800 we put 500 and 800 424 00:25:31.800 --> 00:25:35.720 We put 5 m and 8 m 425 00:25:35.720 --> 00:25:37.720 Write it like this 426 00:25:42.340 --> 00:25:44.700 Generation Radius 427 00:25:44.700 --> 00:25:46.760 It's over here 428 00:25:51.760 --> 00:25:53.760 Put it like this 429 00:25:53.760 --> 00:25:55.760 Here, insert the Generation Radius 430 00:25:55.760 --> 00:25:58.400 and the Removal Radius 431 00:25:58.400 --> 00:26:03.010 We'll write 500, 800 432 00:26:03.010 --> 00:26:07.760 And we'll have to add header, right? 433 00:26:07.760 --> 00:26:11.100 I added the header like this 434 00:26:11.100 --> 00:26:13.760 If you take a look 435 00:26:20.220 --> 00:26:22.800 You need to insert it like this 436 00:26:31.320 --> 00:26:35.760 Turn off Unreal, compile, then open again 437 00:26:48.920 --> 00:26:51.403 We'll check if it's applied well 438 00:26:51.403 --> 00:26:52.683 Delete this 439 00:26:52.683 --> 00:26:56.509 Select it, and it's applied well, right? 440 00:26:56.509 --> 00:27:00.460 And we need to do some project settings 441 00:27:00.460 --> 00:27:04.060 In Edit, go to Project Settings 442 00:27:04.060 --> 00:27:08.200 Go all the way down... and here it is 443 00:27:08.200 --> 00:27:11.180 There are two items related to navigation 444 00:27:11.180 --> 00:27:13.440 There's Mesh and System 445 00:27:13.440 --> 00:27:15.254 If you look at Navigation Mesh first 446 00:27:15.254 --> 00:27:18.729 Scroll down 447 00:27:18.729 --> 00:27:21.394 If you look at Runtime 448 00:27:21.394 --> 00:27:24.100 It has an option for Generation 449 00:27:24.100 --> 00:27:24.980 Here, it's set as Static 450 00:27:24.980 --> 00:27:27.894 This is what we talked about earlier 451 00:27:27.894 --> 00:27:30.466 It means it will make the paths ahead of time 452 00:27:30.466 --> 00:27:32.266 But using an Invoker means 453 00:27:32.266 --> 00:27:34.226 we're making it in real-time 454 00:27:34.226 --> 00:27:40.620 So expand it and change it to Dynamic 455 00:27:40.620 --> 00:27:43.560 And go to the Navigation System 456 00:27:43.560 --> 00:27:47.080 If you look in Navigation Enforcing 457 00:27:47.080 --> 00:27:51.060 There's a check box for whether you'll use a Navigation Invoker 458 00:27:51.060 --> 00:27:53.180 Check the box 459 00:27:55.300 --> 00:27:57.440 Those are the two settings to need to make 460 00:27:57.440 --> 00:28:01.960 Come back, save it all 461 00:28:01.960 --> 00:28:05.760 Then this rectangle changed a little 462 00:28:05.760 --> 00:28:07.760 Earlier, all of these were paths 463 00:28:07.760 --> 00:28:13.160 This time, only the area around the enemy is the path 464 00:28:13.160 --> 00:28:16.120 Push the enemy back a little 465 00:28:16.120 --> 00:28:19.080 Then only this area is the path 466 00:28:19.080 --> 00:28:23.020 Execute, and the enemy walks in place 467 00:28:23.020 --> 00:28:24.840 It can't find the player 468 00:28:24.840 --> 00:28:27.220 If I go closer 469 00:28:27.220 --> 00:28:28.760 If I closer, it can find me 470 00:28:28.760 --> 00:28:33.760 If I go further and run away, it can't find me 471 00:28:33.760 --> 00:28:35.380 To make this more smooth 472 00:28:35.380 --> 00:28:39.040 I'll make the enemy move slower than the player 473 00:28:39.040 --> 00:28:48.180 In Enemy Character Movement, we'll decrease the Walk Speed to about 400 474 00:28:48.180 --> 00:28:53.760 Compile, then 475 00:28:57.300 --> 00:29:00.760 We'll have to implement this now 476 00:29:00.760 --> 00:29:05.360 Go to TickMove of EnemyFSM 477 00:29:05.360 --> 00:29:09.140 We'll write it here 478 00:29:09.140 --> 00:29:13.760 To search for the destination 479 00:29:13.760 --> 00:29:20.760 we first have to explore the route 480 00:29:20.760 --> 00:29:25.160 In order to explore 481 00:29:25.160 --> 00:29:26.760 Put auto 482 00:29:26.760 --> 00:29:28.760 We'll put ns. What this means is 483 00:29:28.760 --> 00:29:31.040 the Navigation System 484 00:29:31.040 --> 00:29:35.220 There's something called UNavigationSystemV1 485 00:29:35.220 --> 00:29:43.760 From here, we'll bring GetNavigationSystem 486 00:29:43.760 --> 00:29:44.980 Here, we put World 487 00:29:44.980 --> 00:29:53.000 Put GetWorld 488 00:29:53.000 --> 00:29:55.300 And this is what we're going to use 489 00:29:55.300 --> 00:29:59.040 Ultimately, in ns 490 00:29:59.040 --> 00:30:03.360 There are two types of FindPath, Sync and Async 491 00:30:03.360 --> 00:30:05.140 Async means asynchronous 492 00:30:05.140 --> 00:30:08.260 We're going to process it synchronously 493 00:30:08.260 --> 00:30:09.620 Put Sync 494 00:30:09.620 --> 00:30:11.560 Here, we put a value 495 00:30:11.560 --> 00:30:14.060 If you look here, PathFindingQuery is inserted 496 00:30:14.060 --> 00:30:17.760 Then PathFindingMode is inserted 497 00:30:17.760 --> 00:30:19.760 These are basic things that are included 498 00:30:19.760 --> 00:30:24.000 so we need to make a Query 499 00:30:24.000 --> 00:30:30.420 So FPathFindingQuery 500 00:30:30.420 --> 00:30:35.760 We'll make this variable 501 00:30:35.760 --> 00:30:36.760 Call it Query 502 00:30:36.760 --> 00:30:42.760 And you need to insert that here 503 00:30:42.760 --> 00:30:47.340 Next, if you look in AI 504 00:30:47.340 --> 00:30:51.860 There's something called BuildPathFinding 505 00:30:51.860 --> 00:30:55.760 This is used to actually build the path 506 00:30:55.760 --> 00:30:59.840 Here, there are 4 variables 507 00:30:59.840 --> 00:31:05.160 FAIMoveRequest goes in here 508 00:31:05.160 --> 00:31:06.760 Then Query is inserted 509 00:31:06.760 --> 00:31:10.760 So FAIMoveRequest 510 00:31:10.760 --> 00:31:12.760 We'll need another variable 511 00:31:12.760 --> 00:31:15.760 We'll call this req 512 00:31:15.760 --> 00:31:17.760 Since req is request 513 00:31:17.760 --> 00:31:20.760 AcceptanceRadius goes in here 514 00:31:20.760 --> 00:31:25.140 We'll put 50, as we said earlier 515 00:31:25.140 --> 00:31:28.760 So if it comes within 50 cm around it 516 00:31:28.760 --> 00:31:31.760 it's processed as arrival 517 00:31:31.760 --> 00:31:33.760 Then for the request 518 00:31:33.760 --> 00:31:36.220 we need the destination 519 00:31:36.220 --> 00:31:39.240 Put SetGoalLocation like this 520 00:31:39.240 --> 00:31:46.360 And we'll insert the destination like this 521 00:31:46.360 --> 00:31:49.760 And we need to put that here 522 00:31:49.760 --> 00:31:51.260 Put req here 523 00:31:51.260 --> 00:31:56.760 Then put query like this 524 00:31:56.760 --> 00:31:59.960 Then through the req 525 00:31:59.960 --> 00:32:07.760 the query gets filled in 526 00:32:07.760 --> 00:32:10.760 To use this, you have to add headers 527 00:32:10.760 --> 00:32:14.740 Mine's already added 528 00:32:14.740 --> 00:32:16.320 It's added like this 529 00:32:16.320 --> 00:32:19.640 Add Navigation System as well 530 00:32:21.620 --> 00:32:24.274 If you search here 531 00:32:30.977 --> 00:32:33.090 Like this, this content here 532 00:32:33.090 --> 00:32:36.583 We'll add the header on top 533 00:32:42.760 --> 00:32:47.850 Then we found the path like this 534 00:32:51.750 --> 00:32:54.300 We'll have to process using this 535 00:32:54.300 --> 00:32:56.440 Here, there's a return value 536 00:32:56.440 --> 00:32:59.860 There's something called FPathFindingResult 537 00:32:59.860 --> 00:33:03.140 We'll receive this 538 00:33:03.140 --> 00:33:06.500 We'll receive it as auto r 539 00:33:06.500 --> 00:33:11.000 And if this succeeds 540 00:33:11.000 --> 00:33:14.300 Ah not r, there's r.Result 541 00:33:14.300 --> 00:33:15.960 Use this 542 00:33:15.960 --> 00:33:17.760 Put == 543 00:33:17.760 --> 00:33:21.760 And this is ENavigationQueryResult 544 00:33:21.760 --> 00:33:23.940 That's this 545 00:33:23.940 --> 00:33:27.760 If you look here 546 00:33:27.760 --> 00:33:29.400 There's success and fail 547 00:33:29.400 --> 00:33:31.500 For Success, what happens? 548 00:33:31.500 --> 00:33:34.760 Tracking happens 549 00:33:34.760 --> 00:33:38.140 Here, since we're heading toward the destination 550 00:33:38.140 --> 00:33:40.760 For destination, if you look here 551 00:33:40.760 --> 00:33:42.760 It's the location of the target, right? 552 00:33:42.760 --> 00:33:44.760 So the destination 553 00:33:44.760 --> 00:33:46.820 since it's the perspective of the enemy 554 00:33:46.820 --> 00:33:48.760 If the player is set as the destination 555 00:33:48.760 --> 00:33:50.620 it just needs to go in that direction 556 00:33:50.620 --> 00:33:52.620 So the content that's previously implemented 557 00:33:52.620 --> 00:33:54.960 will be inserted here as tracking 558 00:33:54.960 --> 00:34:00.080 But for Invoker, in the overall current path 559 00:34:00.080 --> 00:34:02.960 it only checks its own area 560 00:34:02.960 --> 00:34:05.360 So it might be outside the path 561 00:34:05.360 --> 00:34:08.940 In the case of else 562 00:34:08.940 --> 00:34:11.920 the destination is not here 563 00:34:11.920 --> 00:34:14.040 Instead of this, we want to put a random destination 564 00:34:14.040 --> 00:34:15.860 So RandomLocation 565 00:34:15.860 --> 00:34:17.900 We would have to remember the destination, right? 566 00:34:17.900 --> 00:34:21.420 So we'll remember a variable 567 00:34:21.420 --> 00:34:27.880 So RandomLocation 568 00:34:27.900 --> 00:34:31.860 We'll make a variable 569 00:34:31.860 --> 00:34:34.000 Then we'll have to do this first 570 00:34:34.000 --> 00:34:40.400 To use this, to make a random location 571 00:34:40.400 --> 00:34:43.760 we'll declare it in the header 572 00:34:43.760 --> 00:34:44.960 Should we do it at the very bottom? 573 00:34:44.960 --> 00:34:50.380 Like this, as FVector 574 00:34:50.380 --> 00:34:51.760 RandomLocation 575 00:34:51.760 --> 00:34:53.240 It will remember it like this 576 00:34:53.240 --> 00:34:56.480 Then we'll have to fill this in 577 00:34:56.480 --> 00:34:59.000 To fill it in, we'll make a variable 578 00:34:59.000 --> 00:35:02.280 We'll do a bool type 579 00:35:02.280 --> 00:35:06.460 GetRandomLocation 580 00:35:06.460 --> 00:35:07.760 We'll make a function like this 581 00:35:07.760 --> 00:35:12.940 InNavMesh 582 00:35:12.940 --> 00:35:15.760 We'll do this 583 00:35:15.760 --> 00:35:18.010 Then the first factor is the origin 584 00:35:18.010 --> 00:35:20.730 Within a certain radius from the origin 585 00:35:20.730 --> 00:35:22.620 it will mark a point 586 00:35:22.620 --> 00:35:26.920 So FVector origin 587 00:35:26.920 --> 00:35:27.940 Like this 588 00:35:27.940 --> 00:35:35.260 Then float radius 589 00:35:35.260 --> 00:35:38.000 And return the result 590 00:35:38.000 --> 00:35:39.900 Since the return value is bool 591 00:35:39.900 --> 00:35:42.180 Then we'll insert an actual value 592 00:35:42.180 --> 00:35:43.600 and fill this in, so 593 00:35:43.600 --> 00:35:50.800 FVector& like this, then Out 594 00:35:50.800 --> 00:35:54.640 We'll receive the result return value here 595 00:35:54.640 --> 00:35:58.540 OutLocation 596 00:35:58.540 --> 00:36:01.940 We'll make the variable like this 597 00:36:01.940 --> 00:36:03.760 Declare the variable like this 598 00:36:03.760 --> 00:36:08.320 Then we'll make this as an implementation 599 00:36:08.320 --> 00:36:11.880 Make it like this 600 00:36:11.880 --> 00:36:14.220 We need a Navigation System here as well 601 00:36:14.220 --> 00:36:16.660 So put auto ns 602 00:36:16.660 --> 00:36:20.077 In UNavigationSystemV1 603 00:36:20.077 --> 00:36:25.440 GetNavigationSystem 604 00:36:25.440 --> 00:36:31.940 We'll bring it as GetWorld 605 00:36:31.940 --> 00:36:35.760 And in ns 606 00:36:35.760 --> 00:36:38.340 random 607 00:36:38.340 --> 00:36:47.754 Put GetRandom 608 00:36:47.760 --> 00:36:50.360 There are functions here 609 00:36:50.360 --> 00:36:52.360 For Point 610 00:36:52.360 --> 00:36:55.540 GetRandomPointInNavigableRadius 611 00:36:55.540 --> 00:36:59.760 For this, a random value from the overall path 612 00:36:59.760 --> 00:37:01.360 is plotted 613 00:37:01.360 --> 00:37:05.040 Reachable is the location that I can move about 614 00:37:05.040 --> 00:37:08.280 within the random area 615 00:37:08.280 --> 00:37:09.760 the location that it can move to 616 00:37:09.760 --> 00:37:12.180 So we'll bring this 617 00:37:12.180 --> 00:37:14.140 Like this 618 00:37:14.140 --> 00:37:16.840 For parameter, what you need to put for the argument value is 619 00:37:16.840 --> 00:37:18.080 the origin 620 00:37:18.080 --> 00:37:21.280 Insert the origin 621 00:37:21.280 --> 00:37:23.460 Then the radius goes in 622 00:37:23.460 --> 00:37:26.210 The radius, and then 623 00:37:26.210 --> 00:37:29.200 Do FNavLocation & 624 00:37:29.200 --> 00:37:31.240 and we need to put this kind of variable 625 00:37:31.240 --> 00:37:34.560 Then the result from here will be included here 626 00:37:34.560 --> 00:37:41.760 So put FNavLocation 627 00:37:46.980 --> 00:37:49.760 Should we make this the location? 628 00:37:49.760 --> 00:37:51.760 We'll put it in like this 629 00:37:51.760 --> 00:37:53.760 Then it will actually be included here 630 00:37:53.760 --> 00:37:56.760 And this returns bool 631 00:37:56.760 --> 00:37:58.660 Which means there's success and fail 632 00:37:58.660 --> 00:38:00.420 So we'll receive that 633 00:38:00.420 --> 00:38:05.380 bool bResult = like this 634 00:38:07.760 --> 00:38:11.180 And we're going to return this 635 00:38:11.180 --> 00:38:15.000 And if the result is true 636 00:38:15.000 --> 00:38:17.760 If success, then 637 00:38:17.760 --> 00:38:21.260 In OutLoc, what we included 638 00:38:21.260 --> 00:38:24.580 the location value 639 00:38:24.580 --> 00:38:28.120 We'll insert it here 640 00:38:28.120 --> 00:38:30.180 You need to make a function like this 641 00:38:30.180 --> 00:38:33.300 For this function, when it first begins 642 00:38:33.300 --> 00:38:37.440 in BeginPlay 643 00:38:37.440 --> 00:38:40.760 Here, we're going to choose a random location 644 00:38:40.760 --> 00:38:46.240 Since it's origin, put GetActor 645 00:38:46.240 --> 00:38:49.760 since this is component 646 00:38:49.760 --> 00:38:51.760 we'll have to bring it from Me 647 00:38:51.760 --> 00:38:55.760 In Me, GetActorLocation 648 00:38:55.760 --> 00:38:57.000 Bring it like this 649 00:38:57.000 --> 00:38:59.220 For radius, we'll put 500 650 00:38:59.220 --> 00:39:02.800 About 5 m 651 00:39:02.800 --> 00:39:04.620 And we need to put the result 652 00:39:04.620 --> 00:39:06.280 Here, we'll put random location 653 00:39:06.280 --> 00:39:07.760 Then it will fill in here 654 00:39:07.760 --> 00:39:09.760 in RandomLocation 655 00:39:09.760 --> 00:39:12.960 Using this function 656 00:39:12.960 --> 00:39:14.880 we'll fill in this value 657 00:39:14.880 --> 00:39:17.260 Then after filling in like this 658 00:39:17.260 --> 00:39:19.760 Go to TickMove 659 00:39:19.760 --> 00:39:22.220 and we're going to continue implementing this 660 00:39:22.220 --> 00:39:24.160 Then here, we're going to do this 661 00:39:24.160 --> 00:39:26.460 Here, we're going to 662 00:39:26.460 --> 00:39:34.180 first move to a random location 663 00:39:34.180 --> 00:39:38.800 If we arrive 664 00:39:38.800 --> 00:39:40.240 or if there's a problem at that location 665 00:39:40.240 --> 00:39:43.100 then we need to decide a random location again 666 00:39:43.100 --> 00:39:47.340 If there's a problem in the location 667 00:39:47.340 --> 00:39:51.280 choose a random location again 668 00:39:51.280 --> 00:39:52.680 That's what we want to do 669 00:39:52.680 --> 00:39:54.980 So that's why I copied it and brought it 670 00:39:54.980 --> 00:39:58.120 And when it moves, we'll have to see the results 671 00:39:58.120 --> 00:40:02.660 To see if it arrived, we need to know the results 672 00:40:02.660 --> 00:40:04.880 To know the results, we can do this 673 00:40:04.880 --> 00:40:08.040 In reality, MoveToLocation has a return value 674 00:40:08.040 --> 00:40:10.420 So using this return value 675 00:40:10.420 --> 00:40:12.640 we can know the result 676 00:40:12.640 --> 00:40:16.100 Put auto 677 00:40:16.100 --> 00:40:17.440 This is patrol 678 00:40:17.440 --> 00:40:20.800 patrolResult 679 00:40:20.800 --> 00:40:23.560 We'll receive it like this 680 00:40:23.560 --> 00:40:26.700 Oh but we forgot Set 681 00:40:26.700 --> 00:40:29.080 We'll put Set like this 682 00:40:29.080 --> 00:40:32.240 Then since we received patrolResult 683 00:40:32.240 --> 00:40:34.340 we'll compare using this 684 00:40:34.340 --> 00:40:37.360 If we arrived 685 00:40:37.360 --> 00:40:41.760 put patrolResult == 686 00:40:41.760 --> 00:40:44.200 EPathFollowingRequestResult 687 00:40:44.200 --> 00:40:48.120 If you look here, there's AlreadyAtGoal 688 00:40:48.120 --> 00:40:51.260 Then this mean, if we arrived 689 00:40:51.260 --> 00:40:53.760 or if there's a problem at that location 690 00:40:53.760 --> 00:40:56.900 If either of them are true, we'll do this job 691 00:40:56.900 --> 00:40:59.120 Choosing the random location 692 00:40:59.120 --> 00:41:03.020 So we'll configure it like this 693 00:41:03.020 --> 00:41:05.520 Here, put or 694 00:41:05.520 --> 00:41:09.760 and we'll put another condition 695 00:41:09.760 --> 00:41:12.920 For this condition, if it failed 696 00:41:12.920 --> 00:41:16.420 If it failed, we can't go 697 00:41:16.420 --> 00:41:20.360 So if it's the situation where we can't go 698 00:41:20.360 --> 00:41:23.180 so if we arrived or if there's a problem 699 00:41:23.180 --> 00:41:25.220 and we can't go 700 00:41:25.220 --> 00:41:28.120 then we'll choose the destination with a random location 701 00:41:28.120 --> 00:41:30.280 That's what it means 702 00:41:30.280 --> 00:41:34.480 We'll build it like this 703 00:41:37.960 --> 00:41:39.220 It failed 704 00:41:39.220 --> 00:41:41.320 To use this 705 00:41:41.320 --> 00:41:43.760 we'll have to add header 706 00:41:43.760 --> 00:41:45.760 So come here 707 00:41:52.340 --> 00:41:54.700 We'll add this as header 708 00:41:57.600 --> 00:42:00.280 Add it, and we'll build again 709 00:42:02.220 --> 00:42:04.220 Okay now it succeeded 710 00:42:07.560 --> 00:42:10.420 That's how you should configure it 711 00:42:10.670 --> 00:42:13.760 Let's execute Unreal and see if it works well 712 00:42:32.104 --> 00:42:34.304 During execute, in the keyboard 713 00:42:34.304 --> 00:42:36.890 you know the quotation mark to the left of the Enter key? 714 00:42:36.890 --> 00:42:38.740 Press it, and it appears like this 715 00:42:38.740 --> 00:42:40.980 The blue part over there 716 00:42:40.980 --> 00:42:43.460 is the actual path area 717 00:42:43.460 --> 00:42:45.100 The enemy moves 718 00:42:45.100 --> 00:42:48.460 and it chooses a random location within its path area 719 00:42:48.460 --> 00:42:50.760 And when I go closer 720 00:42:50.760 --> 00:42:53.760 since I'm on its path, it comes toward me 721 00:42:53.760 --> 00:42:56.300 And I'll run away 722 00:42:56.300 --> 00:42:57.940 If I run away 723 00:42:57.940 --> 00:42:59.940 If the distance increases, it doesn't come anymore 724 00:42:59.940 --> 00:43:02.160 It plots a random location again 725 00:43:02.160 --> 00:43:05.760 and it moves to that area 726 00:43:08.640 --> 00:43:12.220 Arrive, attack, and if I run away 727 00:43:12.220 --> 00:43:13.680 it follows 728 00:43:13.680 --> 00:43:15.320 or it patrols 729 00:43:15.320 --> 00:43:18.280 That's how it's processed 730 00:43:20.400 --> 00:43:22.040 The problem is 731 00:43:25.020 --> 00:43:25.760 Here's the problem 732 00:43:25.760 --> 00:43:27.620 When it's coming closer and I shoot it 733 00:43:27.620 --> 00:43:30.140 it slides and comes to me, right? 734 00:43:30.140 --> 00:43:32.420 We'll solve this 735 00:43:35.860 --> 00:43:37.380 If it's shoot by the gun 736 00:43:37.380 --> 00:43:38.680 There's the state, right? 737 00:43:38.680 --> 00:43:41.480 Then this is where the states are processed 738 00:43:41.480 --> 00:43:45.980 In the case of Damage or Die 739 00:43:45.980 --> 00:43:48.680 and during attack, for these cases 740 00:43:48.680 --> 00:43:52.380 We shouldn't Move 741 00:43:52.400 --> 00:43:54.520 So for these three cases 742 00:43:54.520 --> 00:43:56.140 Same thing for Idle 743 00:43:56.140 --> 00:43:58.320 Only when it's TickMove 744 00:43:58.320 --> 00:44:01.540 the AI activates Path Finding 745 00:44:01.540 --> 00:44:05.700 For all others, it should stop 746 00:44:05.700 --> 00:44:07.760 So we'll process that 747 00:44:07.760 --> 00:44:11.380 We can't insert it one-by-one 748 00:44:11.380 --> 00:44:13.760 It's difficult to determine where to work 749 00:44:13.760 --> 00:44:16.760 Basically, for switching states 750 00:44:16.760 --> 00:44:18.640 there's the SetState function 751 00:44:18.640 --> 00:44:26.360 So here, if newState 752 00:44:26.360 --> 00:44:31.940 is not MoveState 753 00:44:31.940 --> 00:44:35.160 then stop AI 754 00:44:35.160 --> 00:44:38.920 Let's process it like that 755 00:44:38.920 --> 00:44:42.500 Then put a simple condition here 756 00:44:42.500 --> 00:44:49.180 If newState is Move 757 00:44:49.180 --> 00:44:50.320 That's not it 758 00:44:50.320 --> 00:44:55.760 newState is 759 00:44:55.760 --> 00:44:57.280 Not Move 760 00:44:57.280 --> 00:45:00.040 So put an exclamation point here 761 00:45:00.040 --> 00:45:04.660 If it's not Move, then stop AI 762 00:45:04.660 --> 00:45:08.540 There's the function StopMovement 763 00:45:08.540 --> 00:45:10.460 We want to stop it 764 00:45:13.860 --> 00:45:17.300 Save it again 765 00:45:17.300 --> 00:45:19.760 Let's see the results after compiling 766 00:45:26.960 --> 00:45:30.060 Go closer 767 00:45:30.060 --> 00:45:32.400 Shoot it, and it stops 768 00:45:32.400 --> 00:45:33.940 It comes again 769 00:45:33.940 --> 00:45:37.760 Even when it attacks, once it gets shot, it stops 770 00:45:41.300 --> 00:45:44.880 Let's summarize the content we learned in this unit 771 00:45:45.675 --> 00:45:49.075 Path Finding using the Navigation System Path Finding System Add AIModule and NavigationSystem module Arrange NavMeshBoundsVolume on the level 772 00:45:49.075 --> 00:45:52.492 Create the path by setting the X and Y value of Brush Setting to cover the entire floor Set the enemy to find the path using AIController 773 00:45:52.492 --> 00:45:53.592 Path Finding and Patrol Function using the Navigation Invoker Path Finding For static path creation, if the size of the map on the level is too big, there are functional issues 774 00:45:53.592 --> 00:45:54.792 Solve it by dynamically creating the path using the Navigation Invoker function 775 00:45:54.792 --> 00:45:55.942 Dynamically create the path in the Navigation related menu of ProjectSettings and activate the Navigation Invoker function 776 00:45:55.942 --> 00:45:57.192 - Set the Navigation Mesh of Project Settings as Dynamic 777 00:45:57.192 --> 00:45:58.392 Check off the Navigation Invoker of Navigation System in Project Settings 778 00:45:58.392 --> 00:45:59.342 Adding the Patrol Function Utilize the UNavigationSystemV1 class 779 00:45:59.342 --> 00:46:00.312 If the destination is on the current path, then travel there. If not, set a random location and travel