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:00,870
The sensors.
1
2
00:00:01,110 --> 00:00:05,910
Each sensor implementation is found in the course modules in the sensors section.
2
3
00:00:05,940 --> 00:00:10,080
Here I want to focus on how we can actually use them in a real life use case.
3
4
00:00:10,290 --> 00:00:12,540
Here is the sensor manager.
4
5
00:00:13,350 --> 00:00:20,280
The sensors or the sensor manager is basically a collection of all the sensors that will be applied
5
6
00:00:20,280 --> 00:00:26,190
on each enemy to be able to use one or more to detect its targets.
6
7
00:00:26,400 --> 00:00:32,300
The sensor manager is meant to be used as a modular component containing other modular components.
7
8
00:00:32,310 --> 00:00:37,530
You can either use individual sensors on their own like range detector, field of view, so on and so
8
9
00:00:37,530 --> 00:00:37,950
forth.
9
10
00:00:37,950 --> 00:00:43,320
And you can also use the sensor manager if you want the power of more sensors combined.
10
11
00:00:43,380 --> 00:00:49,500
Basically, the sensor manager has these sensors attached to it and also a timer, which is the
11
12
00:00:49,500 --> 00:00:50,220
PollSensorsTimer.
12
13
00:00:50,370 --> 00:00:55,770
And if you look at the script, there are a couple of things that happen here that are really important
13
14
00:00:55,770 --> 00:00:56,190
for us.
14
15
00:00:56,220 --> 00:00:58,520
So first, I want to mention this signal.
15
16
00:00:58,530 --> 00:01:06,180
So this is how the sensor manager informs other objects that, hey, my target list got changed because
16
17
00:01:06,180 --> 00:01:11,370
some of my sensors detected or stopped detecting some particular objects.
17
18
00:01:11,370 --> 00:01:16,670
And here are some parameters like is using field of view is using raycast, so on and so forth.
18
19
00:01:16,830 --> 00:01:23,610
The initialization is one of the new styles and basically it's a key-pair value dictionary called params.
19
20
00:01:23,730 --> 00:01:29,040
Here for each value we have an enum and it'll say if it should use field of view, if it should use
20
21
00:01:29,040 --> 00:01:35,100
raycast, and then putting those values from the dictionary to the actual variables in this part.
21
22
00:01:35,130 --> 00:01:39,610
Next we have the timer, and this time the timer is connected via code.
22
23
00:01:39,690 --> 00:01:43,050
Instead of going here node -> timeout().
23
24
00:01:43,740 --> 00:01:46,080
I opted for the code version.
24
25
00:01:46,440 --> 00:01:51,750
Basically, in theory, you should always use the code one because you have everything in the code and
25
26
00:01:51,750 --> 00:01:57,480
it's much easier to manage because if some parts are not in the code, you will find it harder to know
26
27
00:01:57,480 --> 00:01:58,890
what exactly is where.
27
28
00:01:58,920 --> 00:02:04,580
This is why I put it here. Then we initialize the range detector and the raycast detector. In the _process()
28
29
00:02:04,590 --> 00:02:06,870
there is one more thing that happens.
29
30
00:02:06,960 --> 00:02:08,940
Since the sensors actually...
30
31
00:02:10,020 --> 00:02:15,510
If you look at an AI, the sensors are actually placed in the non-moving part of the enemy AI.
31
32
00:02:15,600 --> 00:02:20,160
And this means that the sensor manager doesn't move with the actual tank.
32
33
00:02:20,550 --> 00:02:24,840
To fix this, we update it at every frame to the tank position.
33
34
00:02:24,840 --> 00:02:29,970
This will make sure that the range gets applied from the tank origin as well as the other sensors.
34
35
00:02:30,180 --> 00:02:32,490
What happens when the timer gets zero?
35
36
00:02:32,490 --> 00:02:37,590
By the way, the PollSensorTimeout is specified to auto start and not one shot.
36
37
00:02:37,590 --> 00:02:42,990
So it happens all the time with a refresh rate of 0.25 seconds.
37
38
00:02:42,990 --> 00:02:49,560
We will have a final list, which is basically a list of the targets detected by the range detector.
38
39
00:02:49,590 --> 00:02:52,590
These are all the objects around the enemy.
39
40
00:02:52,590 --> 00:02:52,950
.
40
41
00:02:52,980 --> 00:02:58,680
If this sensor manager is using field of view, then we will generate a new list, which is the field
41
42
00:02:58,680 --> 00:02:59,700
of view target list.
42
43
00:02:59,700 --> 00:03:05,040
And this list will actually be combined with the list from the range detector, because the field of
43
44
00:03:05,040 --> 00:03:09,480
view actually works infinitely in in that particular range.
44
45
00:03:09,510 --> 00:03:14,080
We might detect objects beyond the range. In order to combine these,
45
46
00:03:14,100 --> 00:03:20,100
what we will do instead is go through every object from the final list, which is basically what was
46
47
00:03:20,100 --> 00:03:21,360
detected by the range.
47
48
00:03:21,390 --> 00:03:25,620
And if that object is inside the field of view, then we add it to the new list.
48
49
00:03:25,620 --> 00:03:32,100
And once this is done, then we move the field of view list to the final list and basically now we'll
49
50
00:03:32,100 --> 00:03:37,320
have the objects from the combined range with field of view. In the case we want to use raycast
50
51
00:03:37,320 --> 00:03:43,230
if there are objects occluding the enemy, so if the target is in the range is in field of view,
51
52
00:03:43,230 --> 00:03:44,700
but it's behind a cube.
52
53
00:03:44,700 --> 00:03:50,550
let's say. It won't be detected if we use raycast, but it will be detected if we just use field of view
53
54
00:03:50,550 --> 00:03:51,090
and range.
54
55
00:03:51,090 --> 00:03:52,470
How we can fix this?
55
56
00:03:52,470 --> 00:03:57,390
Of course, we go through the final list which now either contains just the targets in range.
56
57
00:03:57,390 --> 00:04:03,740
So this means that either like let's say target is behind the enemy but occluded by a cube, or if it
57
58
00:04:03,750 --> 00:04:07,200
uses field of view, only the targets in front of the enemy.
58
59
00:04:07,200 --> 00:04:10,230
But it doesn't matter because we can use any combination.
59
60
00:04:10,230 --> 00:04:11,010
So we can use it
60
61
00:04:11,080 --> 00:04:14,340
with field of view or with just raycast or with both.
61
62
00:04:14,340 --> 00:04:17,820
We have the final list and then if the target is visible.
62
63
00:04:17,820 --> 00:04:21,150
This actually creates a raycast from the tank to the enemy.
63
64
00:04:21,150 --> 00:04:26,460
And if the raycast actually hits the target and not some other object, then it will append to the list
64
65
00:04:26,460 --> 00:04:30,420
and then the raycast list will get in the final version of the list.
65
66
00:04:30,420 --> 00:04:36,030
And once we have the final version, we can throw the signal out that the list was updated and give
66
67
00:04:36,030 --> 00:04:40,650
the final list to what system actually needs it to make the next steps.
67
68
00:04:40,770 --> 00:04:46,680
This is highly customizable because it allows detection, just the range or any combination range,
68
69
00:04:46,680 --> 00:04:48,150
field of view and raycast.
69
70
00:04:48,240 --> 00:04:54,420
Of course, some functionalities do require to be used in other ways, such as is_target_visible.
70
71
00:04:54,420 --> 00:04:56,580
That means for the raycast detector.
71
72
00:04:56,700 --> 00:04:59,820
This one is actually called in some other parts of the code.
72
73
00:04:59,820 --> 00:05:05,640
When we already have the target and we don't see it at some point, then this is kind of useful. Or the
73
74
00:05:05,640 --> 00:05:11,040
target is in range, kind of similar. Or all the targets in range, just the range detector.
74
75
00:05:11,370 --> 00:05:18,060
Basically these functions are just wrappers on top of specific sensors functionalities.
75
76
00:05:18,090 --> 00:05:24,750
These are useful in particular cases of our AI implementation. But the most useful is the signal
76
77
00:05:24,750 --> 00:05:25,080
.
77
78
00:05:25,080 --> 00:05:27,510
on_target_list_updated. Basically this is the sensor manager.
78
79
00:05:27,840 --> 00:05:30,240
You'll find it in every AI system.
79
80
00:05:30,240 --> 00:05:32,430
It's the first one, the sensor manager.
80
81
00:05:32,430 --> 00:05:36,930
It gets used quite heavily because this is how the enemy detects anything.
81
82
00:05:36,930 --> 00:05:44,120
If we just played this scene and I'm going to use the debug sensors and of course I'm going to spawn
82
83
00:05:44,130 --> 00:05:44,390
an enemy.
83
84
00:05:44,460 --> 00:05:46,140
So this is the range.
84
85
00:05:49,250 --> 00:05:50,480
And this is the raycast.
85
86
00:05:50,480 --> 00:05:50,900
.
86
87
00:05:51,980 --> 00:05:53,120
I'm going to put the camera.
87
88
00:05:53,480 --> 00:05:58,670
If I move here. Now the target is not visible any more from their perspective.
88
89
00:05:59,990 --> 00:06:00,910
But wait a second.
89
90
00:06:00,920 --> 00:06:01,610
Now they follow.
90
91
00:06:01,700 --> 00:06:03,470
Oh! Now it's visible.
91
92
00:06:04,010 --> 00:06:07,990
This was the last position where the target was found.
92
93
00:06:08,000 --> 00:06:09,660
And of course, it checks it a little.
93
94
00:06:10,880 --> 00:06:17,870
This is the final result of the sensors, and you can customize them in the enemy initialization.
94
95
00:06:18,020 --> 00:06:23,570
It's not for this particular video, but, it's in every enemy to be initialized.
95
96
00:06:23,600 --> 00:06:24,560
I hope you enjoyed it.
96
97
00:06:24,680 --> 00:06:25,820
And see you in the next one.
10165
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.