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
Indonesian
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
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
0 Let's now look at the HP system. 1
You'll find this system in the demo folder. 2
prefabs/systems/HPSystem 3
The HP system is a critical part of the project. 4
It allows objects to have life and get destroyed if they take enough damage. 5
Most of the code here is actually to update the health bar (UI) associated with it. 6
And all of the children objects here handle the health bar and the health healing effect. 7
The lasted time, which when it'll get triggered, it'll regenerate health and the health regeneration 8
animation. 9
So, functionality wise HP system has two important features the maximum HP and the current HP. When take 10
damage is called. 11
This is the most important function because when things damage is called, then we need to subtract 12
the amount from the current HP and if it reaches zero. 13
If the current HP reaches zero for the first time, we can check if it reaches zero, but we don't 14
know if it's the first time. 15
This is what is_alive is for. Because if is the first time, then is_alive is true and then 16
it gets false and then it won't be true for the next time the current HP gets below zero. And the HP 17
system actually has two signals on_damage_taken and on_destroyed. 18
When it gets hit on damage taken happens. 19
And this is important for the enemies when they get hit by the player to actually acquire the target 20
and when on_destroyed happens. 21
This is important because we need to actually destroy the object, but you don't want it to be destroyed 22
here in HP system because there are some other steps that need to be taken to destroy other objects (referenced by this one). 23
It's important to get the signal and then use it for later purposes. 24
The other main functionality of the HP system is regenerating health. 25
As you can see here, if the HP system receives damage, the last hit timer gets reset. 26
Once the lasthit_timer 27
is 0 28
Then the should_heal variable is set to true. 29
And this means that from this moment on, the HP will heal itself. 30
How is this happening? 31
At every frame, if should heal is true, then the current HP gets added. 32
The healing factor * delta, and if the current HP is equal or more than maximum HP then we set 33
it to be maximum HP. And then the animation player stops the animation. 34
This is just an animation that sets everything to zero and of course it updates the UI. 35
The UI is basically this bar, which is actually a gradient that has two values. 36
I'll quickly show you what it does. 37
First, we get the gradient from this one and we set the offsets of this one. 38
But when update HP ui happens, it sets the two colors. 39
The first one with index zero is red and then the green one because first we have everything green. 40
The red will start from the left, but it will start from nothing. 41
And then we set the offsets of these. 42
If the player or the enemy gets more and more damage, these will change. 43
I'll quickly show you. 44
This is the red it has like nothing happening, but once it starts taking damage, the offsets move. 45
The red is more than green 46
now. If I go far away, then at some point my healing will kick in. 47
This is the healing animation. It's just basically fade in / fade out for that background, but it will 48
actually slowly heal me. 49
And this can be tweaked here at the Heal Factor, so you can adjust it as much as you want. 50
Lastly, what I want to mention is that the system is meant to be integrated below the kinematic body 51
of either the player or the enemy. 52
And this is needed because once this object gets detected from the projectile collision, they will 53
ask for the HP system directly. 54
It's important for the HP system to be here. 55
Otherwise, if the hierarchy were different for the player and the enemy, then it would have been a 56
mess of a code to make everything work. 57
This is why it's important that the HP system is a child of the object that takes the collision directly. 58
Basically, this is the HP system. 59
I hope you like it and leave me a comment if you did.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.