All language subtitles for 3. Implementing Field of View

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 Field of View example. 1

If in the first sensor implementation was the range where it detected around the enemy, the field of 2

view is actually helpful when we want to detect in front of the enemy specifically by a given angle. 3

Let's give this scene a test and see how it looks. 4

So if I press F6, then we end up with this and the field of view is 60 degrees, so something like 5

this. 6

So of course, right now I am in the field of view, but if I move out of the field of view, then it's 7

false. 8

So basically, this is what we want to achieve in this sensor. 9

By the way, please keep in mind that if we use just the field of view, this will actually propagate 10

infinitely. 11

So basically, if we enlarge these segments to infinity and have the player here, it will be true for 12

every distance. 13

The solution for this is actually to combine both range, because range will give the list of the objects 14

around in a specific distance and then the field of view which will limit it from the front view. 15

Please note that this is really important if you want to use this field of view implementation. 16

But now let's look at the code. 17

First we have the AI, which has the field of view detector this time. 18

And the terrain, the target, the camera and the control are similar to the previous range scene. 19

Let's quickly give this a look because it might be interesting. 20

The main change here is actually the fact that the field of view detector does not use a list, but 21

basically is a query. 22

Is the target inside of field of view, yes or not. 23

So if it is, then it returns true, not false. 24

The target being the target given here. 25

So let's see now what does the field of view detector look like? 26

So I'm going to open this, by the way, it's a new scene. 27

So in the field of view detector, there is just the field of view. 28

So I'm going to head into the script and here the code is quite simple, but there is a little math, 29

especially vector math involved. 30

But don't worry, we'll quickly check it and look into it to see how it's done. 31

So of course we need to specify the field of view angle. 32

This is really important and it's 60 degrees. 33

By the way, please note that Godot uses radians, not degrees. 34

So we need to be careful to convert them to radians when using them. 35

So let's quickly discuss what we have here. 36

First is the enemy position, which is the red circle here. 37

We have the direction which is the forward of the enemy, which is here. Please note that this direction 38

is normalized. 39

It's of length 1. 40

And the target position, which is the target position point, which is this green one and if we run 41

is inside cone, then we need to compute the difference vector, which is the 42

difference between the target point and the enemy position, which is this vector, but it needs to 43

be normalized and normalizing this will mean that we need to put this length to 1. 44

So in this case it will be the small one. 45

Please note that the direction is the same though the origin is the same. 46

I just put it parallel so you can see the small one. 47

Basically this is the same is just normalized and then we need to compute the dot product of these two 48

vectors and then compare it to this cosine. 49

What this means is that if we do the dot product between the two vectors and stating by the Godot 50

documentation. 51

So basically if the angle between them is straight, so that means 90 degrees, then it'll be 0. 52

If it is greater than 0, then the angle is narrower than 90 degrees and if it's more than 0, 53

then the angle will be wider than 90 degrees. 54

But what this means for us is that it will give a value between 0 and 1, and then we can compare 55

it, of course, not directly. 56

We need to compare it to the cosine this of the actual field of view, but it needs to be divided. 57

And of course, as I mentioned, this is specified in degrees and you need to have it in radians. 58

So we need to convert it and then we apply cosine on this. If it's done right 59

let me quickly print this out because it will be much more clear how this works. 60

putting the difference vector. 61

Here, as you can see, it's almost 1 when they're perpendicular. 62

That means the angle between them is basically the same. 63

But if the angle gets changed, then this value is actually the cosine is between these two angles. 64

So as I can move and if I go on the other side is the back, the values will be with minus, but that 65

is not important for us. 66

The important part is the plus values. 67

And I'm going to quickly also put the cosine for reference. 68

So the cosine is for this is 0.86. 69

So basically by using this 70

field of view detector 71

we can detect if the enemy has direct vision of a target in a specific line of sight. 72

What happens, though, if there is an obstacle between the enemy and the player? 73

Well, in this case, we need to use raycasts. 74

Let's find out how to implement that in the next session.

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