Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
A problem that we have is that
Our enemies in our game will spawn outside of the walls which obviously is not
Deal because then well
And this
Is wrong
So
And luckily I think the fix is going to be
Free simple
So let's go to our enemy manager and open up that script
And are my manager
Is responsible for
Spawning
Anna
Now what we are doing to determine response position of the enemy is there a centrally just getting a randomly
Updated unit vector
Then we are multiplying that by the spawn radius of an atom
The player position
Of course the problem being that
If we are pointing in Direction that goes past a wall
Then the enemy will spy outside the war
There is a fix that
I think is going to work really well on the situation
And is essentially that we're going to do a raycast
Subtitled by online-courses.club We compress knowledge for you!
Determine
If this one
Is valid
It's going to be a little bit tricky because we still want the enemies to spawn off screen
So we need to figure out what we gonna do when we
Counter
Collision
And Eric as essentially online along
You check for
Collisions
So we can pick a start position in end position
And we can
Godot
Is there any terrain collision
On this line between them
2 points
If there is a collision
Then what we're going to do is we're going to change the direction
That the enemy is going to spawn
And what we'll do is we'll check it up to 4 time
Rotate
The direction by 90 degrees
Every time until we find an empty space
If that doesn't
Seem super clear yet don't worry it should be a little bit more clear as we get into
So
One thing I'm going to do is I'm going to create a new function that is designed solely for the purpose
Getting a spawn position
Someone who creates a new
Function below the ready method and I'm going to call it
Get
Spawn
Position
And what I'm going to do is I'm going to
Grab this line here
Is this tree line swear
Getting the player
I'm going to copy and paste that up here
Now instead of returning just nothing out of this function
All you want to do is we want to return
Instead
Vectra 2.0
So we gonna play position is going to return
As the position
Should be fine because
We are returning early out of this on timer timer anyway if the player doesn't
So theoretically we shouldn't even get to this point but it doesn't hurt to be ale
Ok
So
Next I'm going to take these two lines and on time or time out the random Direction
In response
I'm going to cut those out
And pay stores
And then in the on time or time out let's go ahead and just replace those lines
We cut by doing
We can replace this actually down here so on this earring line and my back and I what position is it going to sponsor edition
Wishes change that sponsors is near to
Get sponsored
The weekend
Call the function right there
My
And that should
Work just
Ok
So up here if we want this to be functionally the same as what we had before
We can go ahead and return
Spawn underscore
Position out of this funk
So that's going to
Essentially be functionally the same
Where does going to return the position at so
In this part of the function is where we went to actually manipulate the direction if it's not
Appropriate
Where can I want to do a reiki
Check as a man
Earlier in the where we can do that is we actually
Query what is called
The
Space state
An essentially that is the current
8 of the physics objects in the game
Against which we can
Run various checks
In the way that we can retrieve that is
I'm going to write
Get
3
Start
Route
Start work
Underscore 2D
Space
And this is going to be our 2D physics Direct space state is what it's called
And we can do is we can actually
Intersect Ray against
State
And what is intersex
Require as argument while we can open up a documentation and look for intersect
Underscore Ray
Find the definition Henry
Physics
Nextbase
Open that
And we can see that this takes a physics
Aquarium
2D
So let's go and collect
This is an object that we need to
And we need to
Created with
Argument list
Here now this is going a little bit off
My screen here
So we're going to have a from which is affected
A tool which is another
And then a collision mask which is
The same exact thing that we see in our editor over changing the layer and
We are going to be mostly using
Is first three
So let's go back to my manager
Let's just
Above this line
Create a new variable called
Query
Perimeter
I'm going to say physics
Ray
Studio.com cos that's the method
That we were just
In our front position is going to be player.dat global position
Set a start position
And the position is going to be this random
Sometimes spawn rate
So we actually had the stored as sponsors
So I'm going to do if I'm actually just go
Did you copy these
Or rather cut these lines
That we just
I'm going to go ahead and move those on
Ok
So you're cold you look like this
And for the second argument here we're going to pass in spawn position
And then our
Leia
Or our mask ready that we want to check against it's going to be the same so if I open up
Play adjust reel
We have in the inspector here
Nicola and occlusion
You can actually hover over
The mask and I will tell you
B
The thing about
Doing the rear car
Collision
Code is actually need to pass in
The bit value already
Int value that corresponds to the b
The mask
So b 0 as a value of 1 which you can see
In the toilet
When you hover over the terrain Valley
That's the value that were going
So we can write
One in there
That's going to collide with
The train Leia
Now another thing that you can do is
You can actually use
Shift
You want
So
I can say one
Shift
Over 0
If you're not familiar with bitwise operators
Essentially this is just saying
Take
1
Which under the hood has a bit value of 1
And shift that bit over
This many people
And the reason is that useful in terms of the terrain is let's say that I had my terrain
Set
24
Right let's do something little bit
Differ
Let's say 2
So if my lair was too
I would
Type out manually this value
524288
That's not
Really that
Comfortable to wear
Encode Manor
I could do if I could take one
And since this is
B 19 I could shift it 19 bit
And that will
Create
That same Val
So if I had my mask set to let one
I could simply do one
Bit shifted 19 plate
And that you can easily sort of reference
Your mask
Code
With bitwise operators but fortunate
We're simply using
The first bit
As our terrain layer so it
If that's not superclear I'm encouraged you to go ahead
And do some research
Bitwise operator
It's a very handy tool to know
But we'll dropped
Cancer
Therefore now and continue on with our
Ray intercept
So now that we've got are query parameters
Constructed
We can pass those in
The Intern
And we want to store the
So we're going to say virus
Get 3
All that
Another question is what happens if we don't have a recall
If you don't have a rear collision what will happen is result will be now
So we can see if result is
Then that means I just read a comment
Pound
We
Arkley
Else
We have a car
I'm going to write pass in here
This is not
Complaining
That's just a quick of gdscript you've seen as use passe
The Times basically every block of indentation
Need to have
Some sort
Statement or a line of code and passes just basically a placeholder that says
We are doing anything here yet
But we do want to maintain
The inde
We want to maintain the Blacks
Ok so if I was articles
Let's do this just for testing purpose
If the result is no we're going to go ahead and
Return
Spawn underscore position
And if it's not know which is return the player that the whole position this is not
This is not the final behaviour that we're going to watch
Can you remove the return
At the end here
Is the data final functionality that we want but this is going to make it really clear when there was a train collision because the answer is going to
Ride on top of the player
So let's just run this to make sure that we've done everything correct
Subtitled by online-courses.club We compress knowledge for you!
And you can see that already got an anime couple of animals that just spawn on top
Tyres always returning a collision in why is that
That's because
If you read the documentation for intersect you can see that
It says at the end if the radar not intersect
Empty
So this is why reading the documentation is really important
I made the assumption that it would return
Noel if the result
Did not return
Collision
But that's not actually true
Return
Auntie dictionary
Different than no write an empty dictionary actually nom
It just doesn't have anything
We need to do a slightly different check which is a
Result.is underscore
So this is the way that you can check if a dictionary has
Cheese
And
That means letters
North no collision and we can transport position so let's run again
We can see now that hopefully some enemies are going to
Spawning outside of the
Game window and then if I get closer to a wall
You can see now all of a sudden
Enemy spawning on top
As soon as I move into the middle of the screen
That should no longer be happening because we are far enough away from all the wall
So what are we going to do about
In the first part of this lesson that we're going to do if we encounter a collision is a basically just going to rotate
The direction that were looking at
Or that we're looking to spawn the enemy
Rotated by 90 degrees
Sofa demonstration purposes
Here is a corner of my map
Right and then let's say that here is my Play
If I'm choosing to spawn an enemy
In
Let's say
Distraction
And that ends up at the college
If I
Rotated by 9 degrees
It's going to end up looking like this
But I can rotate it by 90 degrees again and like this this is going to end up being empty space
And this 9 degrees is
Collision
So the idea is because our room is a
Tangle it should be the case that no matter what
Corner or wall I end up going to
Have two players here
No matter what direction gets chosen
Like something like that
There will always be a 90 degree in cream
That ends up being clear
Of any colours
I hope that makes sense
Let's go ahead and implement that
In the way that were going to do that is were going to use a 4
Now what is a fool
Afford
Essentially Lazarus
Iterate a specified number of times either over
A specific number of
Elements or a variable number of elements in a
Play some Erasure
And how are you this is
So there are four
90-degree
Instruments that we can do it right
There's the first direction in an iterator by 9
And is rotated by 9
Is 30 by 90 again
So what we going to do is this a 4
I in
4
Now the thing to note is
This is going to increment I
Going to start at zero
When is gonna incremented by 1 every time before Luke and
So when we first run code in this block where this passes
I will be 0
It will run again
I will be one
Anything to note is that this is not
Include
So4
I will never be fair
I will only be a maximum of
3
So that's just something to be aware of when you're using a form
Like this and what we're gonna do is we're gonna move
Holidays code
Except for this
Black
Into
That for loop and make sure everything is properly and
This is what it should look
We're going to declare spawn position above the for-loop so let's go ahead and declare a variable
1 position
And let's just said it to
Player that global position next week doesn't matter live that's actually said it to them
Just so that it initially
2A
Vector
Ok so good to Dad's
Now we're just having a beer and that's fine let's get rid of this via because we can't read it there a variable but we can we
Sign do it in a totally doing here
And we can actually break up
This
If else block so let's
Delete the else
Let's take this if result is my
Invented by 1
An Audi Galway because were in the correct context here
And I want to remove this car
So the thing about 4 so you can return early out of them as well so if your return in a for loop and let's say it's only
The first iteration to actually stop
So we can return early so that we don't have to go through all the loops if the first
So I can spawn position
Is
Valley
Then we're gonna do is we're also going to move the random direction out of this for
Just above
Initialise the random direction to a random
Ok so what we left with is we are left with this look
The final thing that we want to do is we want to put an else after this if result is
MD
And this is the part where we
To change
The
Angle
Of the random diary
So we can say random Direction
Is equal to
Random Direction rotate
And hour angle in here is going to be in
Radiance
So just to make it easy we can do
To read which is a function that will
Degrees in converted to radians
How much pudding
So re-assigning a random Direction
To the random Direction but rotated by 9
And then the loop is going to restart if this else block
Wasn't
Now the last thing we need to do is
Outside of a form
We just need to return our sponsor
As The Returned
Ok so let's just stepped through this logic again just to be extra sure
But everything
So we're going to assign initial spawn position in an initial random Direct
Then we're going to in The Fall
In each iteration were going to take a sponsor
We're going to say it's equal to the players current position Plus
The random Direction which is a unit vector which means a vector of length 1
A x a spawn rate
And those two added together is going to be our new composition that were cancelled
Then we're going to create a raycast query
Using the player position and spawn position
The start and end points
The rake
And we're going to be checking again
The terrain layer
4 Acre
Then we're going to actually do the intersection Ray
Call
To see if that rare
We define a peer interest
Lights with
Terrain
And that's going to be stored in a result dictionary
If the result is of being empty
Then we're going to return that spawn position of here that we talk
If it's not empty
We want to change the random Direction by rotating at 90 degrees
Anna Lowther
To start again
And redo all
And so what's going to happen is we're going to check
Up to 4 raise
Until we find the one
That is not colliding with
Train
And that spawn position the last
Set spawn
Will be
Return
From our
Now what I'm going to do actually to make it a little bit clearer what's going on
Is I'm going to remove this return spawn position from this result is empty and he's a different keyword called
And what break does is that tells the loo
To stop execute
To stop going
Even
The loop isn't tag
Play finished
So this is a nice way in addition to returning
We can just break early out of loop
I think this makes more sense as well
Because we returning spawn position at the end of the funk
Editor seems clear to me like ok we're just going to
What is going to stop
Once we find a spawn position
That is valid and then we'll go
Let's Run the game and make sure all of that is
If I go onto the corner of my map
I should see no enemies coming from this direction
They should see enemies
Coming from
And so far I have not seen any
Please come from outside of the wall
So I think we can say
That this
Is
Fixed
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.