Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,060 --> 00:00:04,330
Let's look now at the waypoint manager and system.
1
2
00:00:04,350 --> 00:00:08,070
I'm going to play the scene quickly and spawn an AI.
2
3
00:00:09,090 --> 00:00:18,300
So when an AI gets spawned, they automatically go into patrol mode and if they find the waypoint
3
4
00:00:18,300 --> 00:00:21,510
system, then they'll move to the closest point.
4
5
00:00:21,510 --> 00:00:26,400
And then, from that point, they'll do the whole waypoint step by step.
5
6
00:00:26,490 --> 00:00:31,770
Of course, at one point (in time), only one instance can use a particular waypoint.
6
7
00:00:31,830 --> 00:00:35,250
Let's see how this all works in this lesson.
7
8
00:00:35,280 --> 00:00:36,630
This is the waypoint system.
8
9
00:00:36,660 --> 00:00:42,060
It might get confusing a little, so I'll try to make sure that everything is straightforward.
9
10
00:00:42,090 --> 00:00:48,540
I'll start here at the waypoint level. And the waypoint here is called waypoint system, but it's actually
10
11
00:00:48,540 --> 00:00:54,540
just a waypoint and the waypoint is formed out of individual points like these ones.
11
12
00:00:55,140 --> 00:00:56,850
These are just position3D
12
13
00:00:56,850 --> 00:00:57,180
.
13
14
00:00:59,730 --> 00:01:00,240
And.
14
15
00:01:01,290 --> 00:01:05,500
They specify where the tanks should move next.
15
16
00:01:05,520 --> 00:01:13,080
If it's following this particular waypoint system. And we have three scripts here, we have the waypoint
16
17
00:01:13,080 --> 00:01:19,320
manager, the waypoint system and the waypoint node. To understand how they work,
17
18
00:01:19,350 --> 00:01:27,510
instead of going through each directly, let's figure out the steps how the AI actually uses this system.
18
19
00:01:27,630 --> 00:01:35,340
So the first contact with the waypoint is asking the waypoint manager: Can you give me the closest
19
20
00:01:35,340 --> 00:01:37,620
waypoint node that is available?
20
21
00:01:37,770 --> 00:01:42,930
Available means that it's not actually used by another AI enemy.
21
22
00:01:42,930 --> 00:01:49,050
So if you go here into the waypoint manager, what we have here is of course in the initialize phase
22
23
00:01:49,050 --> 00:01:51,990
we get all the waypoints that are children to it.
23
24
00:01:51,990 --> 00:01:56,840
So in this case it's just waypoint A but we could have easily made other waypoints as well.
24
25
00:01:56,850 --> 00:02:01,170
And here we have get the closest available waypoint.
25
26
00:02:01,290 --> 00:02:07,200
So what this does, it goes through all the waypoints and if it's in use, then it just skips it.
26
27
00:02:07,200 --> 00:02:10,020
And if it's not in use, then it means that it's free.
27
28
00:02:10,080 --> 00:02:16,530
And then inside of this, not only that we get the waypoint, but we also get the closest node from
28
29
00:02:16,530 --> 00:02:17,940
that particular waypoint.
29
30
00:02:17,940 --> 00:02:21,300
So if we look back in the scene, we have four nodes here.
30
31
00:02:21,300 --> 00:02:22,860
1, 2, 3, 4.
31
32
00:02:22,860 --> 00:02:25,200
The closest node from the player would be this one.
32
33
00:02:25,590 --> 00:02:31,650
So usually since most of the A's get spawned here, they either get this one or this one has points
33
34
00:02:31,650 --> 00:02:32,220
going back.
34
35
00:02:32,220 --> 00:02:33,570
So you get the closest point.
35
36
00:02:33,570 --> 00:02:38,370
Of course, we don't know for sure if this particular waypoint has the closest node.
36
37
00:02:38,430 --> 00:02:41,790
We just know that this is the closest node from this waypoint.
37
38
00:02:41,970 --> 00:02:47,130
When we call the get closest node from the waypoint we know is the closest from this particular waypoint.
38
39
00:02:47,130 --> 00:02:53,940
But if it has more waypoints, some closer nodes might be even more closer to the actual position that
39
40
00:02:53,940 --> 00:02:55,020
we are specifying here.
40
41
00:02:55,020 --> 00:03:00,300
So we need to make sure that we actually take care of this and we get the closest, closest point.
41
42
00:03:00,310 --> 00:03:04,890
So to provide the better example, let's say I duplicate this and move it a little.
42
43
00:03:04,890 --> 00:03:05,340
So...
43
44
00:03:08,930 --> 00:03:11,480
Let's now say we have two waypoints systems.
44
45
00:03:11,480 --> 00:03:13,780
So Waypoint 1 and Waypoint 2.
45
46
00:03:14,420 --> 00:03:21,830
It will get the closest point from this one and from this one, and it'll determine based on the position
46
47
00:03:21,830 --> 00:03:24,050
let's see, it's this one is the closest one.
47
48
00:03:24,830 --> 00:03:30,020
And if this one is free, then it will basically return this node to the player.
48
49
00:03:30,020 --> 00:03:32,780
So this is how this functionality works.
49
50
00:03:32,780 --> 00:03:39,470
Basically, it just checks all the available waypoints that are not in use and then returns the closest
50
51
00:03:39,470 --> 00:03:40,520
point for each.
51
52
00:03:40,520 --> 00:03:45,890
And then once the player decides, Oh, this is the closest point to me, I'll use this one.
52
53
00:03:46,040 --> 00:03:50,210
So basically this is what happens at this level and not much more.
53
54
00:03:50,330 --> 00:03:56,960
So the waypoint manager just knows all the possible waypoint systems and gives the closest available
54
55
00:03:56,960 --> 00:03:57,620
waypoint.
55
56
00:03:57,860 --> 00:04:03,230
Now if you look one level down where the waypoint level is, the waypoint system actually here we actually
56
57
00:04:03,230 --> 00:04:05,690
have the specification of the points.
57
58
00:04:05,690 --> 00:04:12,830
Every children often waypoint system is actually a 3D position that the enemy needs to do in sequence
58
59
00:04:12,830 --> 00:04:15,350
first to get all of the children. In the _process()
59
60
00:04:15,350 --> 00:04:17,540
we basically just display them
60
61
00:04:17,540 --> 00:04:18,560
with a debug line.
61
62
00:04:18,680 --> 00:04:21,950
So this is just for visual purposes, no functionality here.
62
63
00:04:22,040 --> 00:04:25,340
And, in here, we do have three main functionalities.
63
64
00:04:25,340 --> 00:04:26,450
Get the closest node.
64
65
00:04:26,450 --> 00:04:29,780
This gets the node closest in this particular waypoint.
65
66
00:04:29,780 --> 00:04:35,840
So of course it takes a position and then goes through all of the points here.
66
67
00:04:36,440 --> 00:04:42,470
And if it detects an even closer point, then it updates the closest node and once the points are finished,
67
68
00:04:42,950 --> 00:04:44,660
the closest node is returned.
68
69
00:04:44,690 --> 00:04:51,110
This is only used in combination with the waypoint manager because once the enemy AI has locked down on
69
70
00:04:51,110 --> 00:04:57,530
a particular waypoint and it moves to a particular position, then they will use the get next node.
70
71
00:04:57,770 --> 00:05:03,800
So this one works as follows: it has the current node, which is specified here and then iterates through
71
72
00:05:03,800 --> 00:05:10,100
the list of waypoint nodes and if we find the current waypoint in the list, then we know that the next
72
73
00:05:10,100 --> 00:05:12,320
one is where it should go next.
73
74
00:05:12,440 --> 00:05:17,360
And of course we need to prevent if it's the final point, we need to go to the first point.
74
75
00:05:17,360 --> 00:05:20,900
So basically this is how we can loop a waypoint system with the movement.
75
76
00:05:20,900 --> 00:05:27,380
Lastly, we also need to trigger the waypoint use so that no other enemy can acquire this waypoint
76
77
00:05:27,380 --> 00:05:27,770
system.
77
78
00:05:27,770 --> 00:05:30,320
So this is actually called by the children.
78
79
00:05:30,320 --> 00:05:31,040
I mentioned this.
79
80
00:05:31,340 --> 00:05:36,740
It should not be called at this level because the waypoint manager will give the enemy a waypoint node,
80
81
00:05:36,740 --> 00:05:40,790
which is actually a position and that waypoint nodal trigger this one from the parent.
81
82
00:05:40,790 --> 00:05:42,950
And then that's basically it. The last level
82
83
00:05:42,950 --> 00:05:44,360
here is the waypoint node.
83
84
00:05:44,390 --> 00:05:46,400
If you go inside here, it's quite simple.
84
85
00:05:46,400 --> 00:05:52,010
It takes the parent as the waypoint system, it triggers the waypoint use from the parent and it also
85
86
00:05:52,040 --> 00:05:53,960
gets the next node from the parent.
86
87
00:05:53,960 --> 00:06:01,850
So the waypoint system is actually an in-between component because get closest node is used by waypoint
87
88
00:06:01,850 --> 00:06:07,670
manager, get next node and trigger waypoint use are used by its children.
88
89
00:06:07,670 --> 00:06:12,920
So you as a developer don't actually need to go here and do anything because you either go to the waypoint
89
90
00:06:12,920 --> 00:06:14,870
manager to query it in the first place.
90
91
00:06:14,870 --> 00:06:20,450
And once you acquire a particular point, let's say this one, then you either query for the next node
91
92
00:06:20,450 --> 00:06:24,380
or you triggered the waypoint use once you get it in the first place.
92
93
00:06:24,950 --> 00:06:25,880
And that's basically it.
93
94
00:06:26,090 --> 00:06:27,800
And then the patrol part of the enemy AI.
94
95
00:06:28,100 --> 00:06:33,890
We'll look more into how this system is actually used to get the node and get to the position.
95
96
00:06:33,890 --> 00:06:37,010
I hope you enjoyed this lesson and I'll see you in the next one.
10169
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.