All language subtitles for 2. Implementing Range Detection

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

0 Welcome to the sensor implementation. 1

And the first sensor we are going to look into is the range sensor. 2

First, let's give this scene a quick test run so you can see what we are going to achieve in this module. 3

We have the enemy in the middle of the scene that has a range specified by this wire sphere. 4

If my player, which I can move with WASD or the arrow keys goes into the sphere, then it is detected, 5

as you can see here. 6

And if it's out then it's false. 7

This is a quite simple sensor. 8

It's not useful in cases where, for example, when you want field of view, but in some other cases, 9

for example, turrets or things that have 360 view, it works great. 10

Plus it can work with other sensors together. 11

So let's see how this is made. 12

Okay. 13

Now here we have the scene. 14

And as you can see, there are a couple of different components here that I want to discuss before diving 15

deep. 16

So we have the AI in the middle, which is basically the AI instance that has the sensor. 17

We have the terrain, which is basically just the cube. 18

We have the target, the camera that we can see through while the scene is playing and the control, 19

which is basically just some UI elements. 20

Let's quickly look at the target because this is the player. 21

So here there is a kinematic body. 22

It's important to be on layer one because the detection will be on layer one. 23

It has a mesh instance, which is a capsule and a collision shape. 24

But don't forget, it's really important to have the collision shape. 25

In my case, it's a capsule shape, but any shape works. For the target script if we look into it right 26

now because it's quite easy, it just sets up the type of the enemy using the meta functionality and 27

the collision. 28

This is not relevant, but it's used to detect the body which has the collision. 29

If we go back to the scene, we also have the range sensor test that has a script attached to it. 30

And this is really important because this is the debug script. 31

What this debug script does is of course initializes the range detector. 32

By the way, here is the radius. 33

So if you increase this, then the sphere will get bigger 34

(the detection sphere). First part says if it's enabled or not. 35

And lastly, it gives the AI (reference). 36

In this particular example, this is not so useful, but in the real world example, we want to avoid 37

detecting itself, so we don't want the AI to be able to detect itself. 38

So this will actually work to remove the the AI from being detected. In the process function which happens 39

every single frame we do have move up and down and left and right which move the target up, down, 40

left and right. 41

Also, the range detector provides a target list which we query all the time, every frame to see if 42

its size increased from zero. 43

And if it does, then this statement will return true and will appear on our UI that is_detected is 44

true, otherwise it will be false. 45

Now let's take a look at the AI and 46

what does it have. 47

Basically, the AI is just a node with a mesh instance, which is a capsule, as you can see. 48

But the important part here is the range detector. 49

Currently, there is no physical part that can interact with the range detector from the AI. 50

But in a real case scenario, there will be. Let's look at the range detector. 51

By the way, I created a special scene for this to make it useable as possible. 52

So if I click open an editor, it will open the new scene. 53

And here there are a couple of things really important. 54

First, we have the area collision and it's really important to create this area collision because this will 55

determine the collision between this object and what comes into it. 56

Please make sure that monitoring is set to on. Monitorable means that it can be queried by other things. 57

But since we are the ones that are monitoring, we can safely put this to off. 58

We need to put the mask on one because the layer of the player is on one. 59

So we need to make sure this is on one. 60

The collision shape for this is a sphere. 61

So this is put as a sphere, but this will not matter because you'll change it through code because 62

you want it to be dynamic. 63

There is also an immediate geometry. 64

This is for debug purposes. 65

But what I can tell you about this is just the simple immediate geometry node. 66

It has a material of yellow without light, so it's unshaded. 67

And also here it's quite simple code, but basically what it does, it just creates a sphere out of 68

primitive lines. 69

Using the radius provided by the collision sphere in the range detector. It's nothing fancy, just for visual 70

debugging reference. 71

Now moving on to the main part of this is the range detector script. 72

And here's the full script we're going to look. 73

Into each part and see how it works. 74

Basically, starting from the top, we have the extends node. 75

It can also extend the spatial, since it's a spatial, this one. 76

It provides two different signals which in some cases you might use, in some cases you might not. 77

But on the target enters this range detector, it will signal that fact and also send what target actually 78

entered or what target exited. Next 79

it will have a target list continuously updated with all the targets that are monitored in that range. 80

The collision shape is the sphere shape mentioned here and this will be used to make the correct size 81

when we actually customize it. 82

The parent is the actual component that we want to take out from the potential target list. 83

For example, if the AI detects itself, we don't want it to be in that list because it would be redundant. 84

Is enabled of course. 85

Is self-explanatory true if it is enabled false if it's not. Here we have a couple of different functions. 86

Two of them are custom and two are signals from the area collision. Starting with the initialize it says 87

is enabled, custom range. 88

This is what actually gives the range of the whole sphere and the parent the collision shape as I mentioned 89

before, why this is not important, this sphere shape, because we are going to create the new sphere 90

shape and we are going to set the radius of the sphere shape to the custom range that we provided. Next, 91

of course, we need to initialize is_enabled and parent from these two values. And for the collision shape, 92

we need to of course set it correctly with the one that we currently created. 93

And if is enabled, of course the immediate geometry gets the collision sphere as well. 94

The main part of this is the function called is target in range, which will give true or false. 95

But as you can see, there is no query to physics, but more a query to if the target is in the target 96

list. 97

And this is because the target list will automatically get updated with things that come in or out of 98

it. 99

And this happens because of the next two things. 100

So how we can hook up the signals? 101

Well, if we go to the area and we go to the node and on body_entered. 102

So it's body not area because this one is the area, the player kinematic body is a body actually in 103

here. 104

Just say connect. 105

Of course we need to put the range detector because this is the script where it has the connection to. 106

And when you go back, we repeat the process for both of them. 107

When you go back, we end up with these two functions and as you can see here, they are connected. 108

What happens here is that the area detects a target that entered and then the target gets processed 109

into an enemy. 110

Here I have a singleton called globals which has get enemy from collider. Will quickly go into that 111

in a second. 112

But before that, if the enemy is not null, that means that it was processed correctly and the target 113

list does not contain the enemy. 114

This means basically that the enemy is legit and it can be added to the target list since it's a new 115

enemy detected. 116

First, of course, we need to prevent the self collision. 117

What I said to the parent, we don't want the enemy to be itself. 118

And then we use append for the target list, which is basically a way to add new elements to the list. 119

And then we emit the signal. 120

We send the event that, hey, this target entered the range. In the case, 121

for some reason this happens and the enemy detected was already in the range. 122

Then it won't be counted as a new enemy getting inside this list. 123

The same happens for the target exit. 124

So basically it still determines if the enemy is valid. 125

And then if enemy was actually in the target list and if it was, then it needs to be erased. 126

And then another event is released saying that the target is out of range. 127

Now let's quickly look at get the enemy from collider. 128

So here is basically a physics collider. 129

So in this case. 130

What we're going to receive is probably this kinematic body. 131

So keep this in mind. 132

And the kinematic body, as you remember, we have this small script that has a meta tag called type 133

with the value enemy. 134

And this is really important in what's to come, because if we go here with control, click basically 135

it gets the enemy from the collider is just a value and then it checks if it has the tag and that 136

means that it is detected and if it's not detected, then it will return null because there is no enemy 137

to detect. 138

But then, of course, we need to process the tag and to see if it's actually an enemy or a player and both 139

of them are labeled as enemy. 140

This actually happens because the plan is: for the enemy to target both the player, but also enemy 141

AI from different teams. 142

So this has to happen in order to do this. 143

If the tag is not enemy and not player, it might be a third party type, like for example, obstacle 144

or something else. 145

And we don't really need to count it as a target. 146

So for this we return null because we don't need it. 147

Now, if we go back to the range scene and test it again, this is the result of this. 148

And if we quickly check the target list. 149

So I'm going to take the target list. 150

I'm going to print the target list. 151

And as you can see, the target list is the kinematic body. 152

But if I step away from the range, the target list will be empty. 153

Go in the kinematic body. 154

Out, empty, in, out and out. 155

Very simple. 156

This is basically the range sensor. 157

Now let's move over to the field of view sensor.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.