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
One major thing that are lacking in our game is player health
Currently the player has no way to take damage in no way
Die
Salt we're going to get started
Implementing that
In this life
So
We already have
Health composed
And remember how I said we designed it in a way that we can read
Set the cross
Odyssey
So that's exactly what we're going to do so go ahead and open up your players
By clicking me open in editor button from the main scene
Let's go ahead and then stands in Uno
With control
Search for health
Composer
And that and then we'll move it
Above the above
Tell component how much health 312 player to have well this is going to be largely up to you and how you
But I guess I will just leave it
10 for now
And then we'll see you how
Hatfield
Ok so that's simple enough
The problem is we need to be a
How to change the health
When the player come
Collision
With an n
Subtitled by online-courses.club We compress knowledge for you!
And how are we going to do that
I'm gonna do is we're going to create another area 2D
In addition to the area to do that we have here
Dad is going to be able to detect enemies enter
The player
Animal use that as the base
Dl10
Switch to the player
So let's go ahead and rename this existing area too
To pick up area
To Dean
So that it better describes what this is
Purposes animal create another node on
Can you search of type area2d
And we'll go ahead and move it just under the pick-up area
What's this collision area
2D
And I'm going to go ahead and add a child node
Colours and shapes
Utilita
Let's go down to the ship resource
And create a new
Circle shape
And it looks like we can turn this down to about
Which roughly
Matches the player size
And then select the collision area to DW on the keyboard for the move tool
And we're just going to move
To roughly be centred around
The player
I think that looks ok what I am going to do is I'm going to go back to the collision shape to the underneath
Change the radius to something like said
Remember it's not necessarily a bad thing
Going to have your collision area by a little bit smaller
And if you want to see this letter you can read the collision area 2D
Above the Sprite just so we can get an idea
How dad's look
Can I take it
Fine
Ok
So
What's going on open up the place Crewe
And we want to
Detect when an enemy enters a collision
So
What
Do we need
To do
We need to configure the collision layer in the collision mask of the
An area
To be able
You detect enemy
Stop
Scroll down
With collision area2d selected
And we were
To make this not exist on any layer
And we wanted to look for collisions with me
Me and looking at
So central going to be doing is let me open up of the basic anime scene Justice
I'm going to
Turn the TV mode
So what we can figure it out our collision area to the
To look for it
Player seen is we're looking at centrally for this collision shape
Of the
So the small one
The inside
And why is
Because the basic enemy
Actually this basic enemy exist on the enemy collision layer so this is the this so I'm going
His Highness
Hide the hurt
Components of this blue circle right here is the thing that we wanted to
So is actually incorrect that's not the enemy layer
That is
The
Enemy collision
So we want to look for enemy
Collision
Instead
So I'm gonna go back to my player
The collision area 2D
Change the mass
From
Two enemy collision
That's going to be looking for the smaller area the same collision shape that the enemy uses for
Collisions against the train
Ok
Now the thing about the basic enemy
And as listening to that end
Collision layer
Collisions is that this is actually
Type
Barry
Instead of
So this is a body to do
Another area to
And so we're going to have to use a slightly different signal in our area
Detection
In the playlist
Gutter collision area today let's go and open up the playlist
And what we want to do in the ready metal that's removed this past line
And Wilder in here let's go ahead and remove
The comments as well because we
So we're going to
Collision area2d
A reference that with the dollar sign shortcut
Then we're going to say body and
So she had a different an area entered which we've been using
Previously
Because we're going to be listening for thing
That have expired
And we're going to connect
On Barry
And let's Create that function at the bar
On body enter
And by the way you'll notice that we are
Putting all of the signal functions at the bottom
That's just personally how I like
To organise the code
To put all the Single functions at the bottom and prefix
Was on
Underscore
So it's very clear that these are sick
And let's go hence like the Cleveland area to
In our
Seen here and we're going to go to the notepad to look at the singer
We can see the
We have Barry entered and body Exeter Sid
And the body that's coming in is a no too deep so let's go ahead and say
Other body
And that subtype notary
Corn at the end and then pass
Before we go any further how do we want to play that actually take damage with the thing that I'm in Vision
Is that
The player will take damage
While
There is an enemy colliding with
So what needs to happen
We need to listen for a body and turn signal
We need to
Doodle
Periodically while a body is inside of the play
Right so we don't want to damage every frame because I would be unfair the player died in
So I'm thinking every
A second or so
While there is an enemy
Colliding with the
We deal
So what we need to do to achieve that is we need to listen for body enter
But also body exit
And we need to make sure that it work
With multiple bodies so imagine the situation
For all collide with the player at the same time
We are going to want to listen for those but we don't want to multiply the damage the player is taken by 4
We just want to say all the players taking down
When those bars
Exit the player or when one body except the player we still want to keep doing damage because they're still three other body
On a plate does that makes
So I sent you all we need to do is we need to keep track of the number of bodies that are colliding with the player and as long as they
Number of bodies are greater than 0 we need a periodic Lindale Dam
And Simon show you how we can accomplish
So
As I mention we're going to need a listen for body exited as well
Time is going to duplicate this line
By copying pasting
And I'm going to change this to buddy x
And we are going to change this connector method to on
The Exeter
Create a new function to buy
On body X-ray
Again looking at our no return over here
That
Passes in a body argument as well so we'll just say other bar
Note
I'm alright pass
Set the top of a player script create a variable
I'm gonna call this number
Barry
Is equal to
Ok on body enter
We're going to get rid of this pass line
Do number colliding bodies + = 1
And then on body excellent working to do -
Colliding bodies
Equals
Now we need to
Deal damage to the player periodic
Let's create a timer on
The players and child node
Timer
Guide and drag that up above
Pick up area two
Call this damage interview
Timer
Let's go to the inspector
I'm going to change this wait time to
Return to One Show
Never Gonna Leave artist
Off
So what we need to do when the body is entering
Is we need to
Deal damage
So what I'm going to do is I'm going to write a new function called
Check
Deal damage
Something like
And what I'm going to do in here I'm going to say if number
Colliding bodies is equal to 0
Where is gonna return so we're not going to do anything if there's currently no colliding body
Otherwise what we're gonna do
Is we are going to
Deal damage to the player
So what we're going to do is reference the health component
And then we're going to do dot damage
We don't have this type so we're not going to get any
But if you need to see what the health components methods are even is open
Add script and you can see that we have a damage
Function right here was damaging
So I'm just going to go back to the play script and I'm just going to deal 1 damage
Then what's going to happen is I'm going to reference the damage interval time
With dollar sign damage in triple time
And
I'm going to start
So there's a couple of things so basically we want this to deal damage
When the number of Llandudno
0
We also want it to only deal damage if the damaged interval timer is stop
So let's get a reference for this damage in trouble timer so we don't have to
Using the star sign notation
I'm gonna go to the top of my script
I'm going to write on red
Via
Damage underscore interval
Subtitled by online-courses.club We compress knowledge for you!
Underscore timer is equal to
Damage internal time
And again
This means that
When were sewing missing in a variable we don't have to go to the same tree
To get that node every time
Just a little bit more can
Mirena replaced
Dollar sign damaged interval timer with Arnie
Variable and then in the top here if number of colliding bodies is equal to 0
Or
So that's 2 pipes for the or
Damage
Interval timer
Is stop and we actually want to
What's this tune
Stop which basically means
If our number of claim bodies is 0 or H damage interval timer is running them
Because we don't want to deal damage while the timer is still running that's basically just a graze
Which the player count
Sauna on body enter what we want to do is we want to call
Deals
Now the problem here
Is that we're only calling this now
When
An enemy enter
The play area
But what happens if that enemy is on top of the player
4 more than half a second
There's nothing that tells this to be called again
And so what we're going to do is we actually going to call this function
When the damage interval timer
Times out
Let's go back up to are ready
Function
And we're going to say dammit
Interval timer
Time out
Dartconnect
Water coolers on damage interval
Timer
Time out
Your notice
That's rather cause I'm being very verbal
In my function name
And why is that because it's just
Easier to read
More descriptive variable names and
Functioning
So how include you do the same
You can go to any piece of old code
As your building out your game
As long as you using descriptive variable names and function name
You're going to have an easy time wrapping your head around
What the code is doing
If you haven't seen it for a while
So I'm going to create that function at the bottom
On
What was it called on damage introvert
Timer time
And what are we going to do
In this function
We're going to rain
Check deal damage
Now you could just put cheque deal damage
Here
As the signal connection
But again I don't like to do that I like to have a
Function explicitly handles the signal
Omission
It just seems to make more sense
To me
So when the timer runs out you're going
Calling check deal damage again
So that means that as long as there is an enemy
The player
Check deal damage is going to keep being cold
Every have a
Tell me some cities in
So let's say that
The damage interval timer is at .4 seconds and is running but the enemy exit
When is timer countdown
What's going to happen
It's going to see that all there's no more colliding bodies so we just
So we've got the appropriate safety is in place so when I go
We doing erroneous data
To the
Alright and then the last thing to do
Is 2 let's just print for debug purposes the player
So print
Dollar sign health component
And let's go back to the health components
I've got current
So we can reference that
By simply just doing current
Underscore
Toilet seat for work so I'm Gonna Run the game
I'm just going to shrink the window so I can see my output console at the bar
We see 987
X5
So yeah that is counting down appropriate
Hello that are player even gets freed from the scene
When
Selfridges
And you can see that the fruit of our defensive programming have worked because
Despite the fact that there's no player in the scene anymore because he got q-free
Are Games still running in housing crash and we have no errors in the console why because we were taking care
To make sure that we are checking the validity of the player that we were referencing
And so the enemies they don't have a target to move through so they just
The camera is just
The timer is still going
So that's all that's very good demonstration of the benefits of
Defensive Pro
Alright so we've got basic hair
Damage logic in
For the player
And the next step is to make it visible on screen
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.