0:19 is where I'm commenting from. At first, I would think that there would be two health bars overlaid. The top bar moves down by percentage based on the hit. The second would stay, and only move down if the top bar hasn't moved in some arbitrary length of time. If the top bar value
Amazing tutorial, especially the fact that you use the Healthbar as a component. Too many people just add canvas layers or add a healthbar directly to their scene. Thank you!
I tried to implement this myself the last two days in my 3D isometric, but for the player health (tried to implement it into Camera script which I set as parent of the HealthBar). Thank you so much for this! Very nice and clear explanation, even though the part writing the actual script was a bit fast. Can't wait to get home and try it!
Bro this works wonders! You explained it so perfectly and it actually works! Also the way you set it up it can be used for multiple different things such as players and enemies! Thank you so much! Liked the video and subscribed!
quick suggestion: instead of making the damage bar snap to the right value after the combo, you can use a tween to make it move towards the right value! so it's smoother
In case of someone that needs that, the way I did is the following: 1: Disconnect the timeout signal from the Timer of the HealthBar 2: Change the set_health function: func _set_health(_new_health): var previous_health = health health = min(max_value, _new_health) value = health
if health timer.time_left: timer.disconnect("timeout", _on_timer_timeout)
timer.connect("timeout", _on_timer_timeout) timer.start() else: damage_bar.value = health
I had an issue with the implementation because the health variable is assigned before setting the max_value and value variables. As a result, when the setter for the health variable is called during initialization, it used the wrong values for max_value and value. To fix this, i simply set those two variables before i set health.
This should be standard in all video games because unlike numerical HP displays, a small damage is barely noticeable if displayed as a bar without a damage indicator where as numbers, you'll see the rightmost digit change (assuming no damage number shows) as numbers are very distinct visually than a bar. At 5:25 I would recommend swapping the damage and health to represent the amount healed in the event that HP is greater than previousHP.
The init_health function will not work because we have changed the var health : set function. In init_health the first two lines should be like this: max_value = _health health = _health then it will work correctly.
do you know why I'm getting null value on damage_bar in set_health function and same in init_health ? I did one to one from video changed what you wrote and still nothing
If you get an error like this: “Attempted to call function 'init_health' in base 'null instance' on a null instance.” Most likely you are trying to change values on a heatlhBar that has not yet passed _ready(). If you are trying to set the value of a heatlhBar, during the _init() of whoever owns it, move that to _ready(). If you just can't change the value, check again that you haven't made a mistake in the code. Check that you may have forgotten @onready somewhere.
Thanks, this was excellent, and I used it to make a 3D version that takes this and just makes a Sprite3D "Billboard" of it for my 3D game. I also put in a little tween as some have asked for so that the white part moves smoothly after the timer timeout.
No, I wanted to leave the health / damage / death implementation up to the viewer so the healthbar doesn't depend on it. Any way you approach doing health will work with the health bar. Here I used on_dead as a function defined in the parent Enemy script that can be overridden if needed. Also, var health is defined in the parent Enemy.gd so I call super._set_health() to trigger its setter first.
@@DashNothing thanks, is there any way you'd be willing to share your code for that section? I've just started game design and have found that putting together ideas from different videos/guides pretty tough.
Really cool tut, and I followed perfectly fine until I got to 6:38. You just already have this function set up for _set_health but obviously I wouldn't and don't have a function like that already set up. So where would I add the "healthbar.health = health" statement???
@@hrothgarnogar You update the healthbar's health any time your enemy's health changes. In this case I have a var health on the enemy and a setter function _set_health which gets called every time you try to assign a new value to a variable. Here's a little example of setting up getters and setters: forum.godotengine.org/t/how-to-use-godot-4-setget/5975/2 Of course, you don't have to update healthbar's health inside a setter function. You can also do it when the enemy gets hurt, wherever that might be in your code. It's up to you.
This means you didn't get the reference to the healthbar node in your enemy script. Either you didin't add the healthbar to the scene, didn't write the @onready var healthbar = $... line, or the name of your healthbar node and what you're trying to get in the @onready line don't match. Hope that helps!
@@DashNothing Month late, same issue as commenter above, but I've tried all of your fixes and it still is not working. Also says that health is not declared in the current scope but can that just be fixed by declaring health as a variable in the scene? I'm using it for my player character if that helps.
@@ponshop1742 Definitely add the health variable to your player script if that's where you're using the healthbar. Did you add the healthbar to the player scene? And did you use the instance scene button (chain icon)?
@@ponshop1742 The problem is your var healthbar is set to null because Godot couldn't find the healthbar in the scene. If the healthbar is in the scene also check if the spelling of the path to it is correct on the line @onready var healthbar = $... To make sure you can delete the path and just drag and drop the healthbar from the scene tree into the code editor. This will generate a correct path to it.
thank you so much for the great tutorial. one question. in _set_health() (4:46), why do you write health = min (max_value, new_health) instead of just saying health = new_health? Does it make any difference?
I don't underatand what max_value is doing or why we need to use min() instead of just using new_health? Edit: ok I think I get it, the _init_health parameter is passed in from the enemy script's _ready function. That means that the init_health function is only called once to set the max_value once, meanwhile newHealth changes each time var health is updated. min(Max_value, new_health) prevents the value from exceeding whatever is initially define as the maximum health
I'm getting null within init_health(_health) funtion in health bar and set_healthbar function getting null with damage_bar.value = health any ideas what I did wrong, I did exactly 1 to 1 from video
@@Lutnar You have to make sure yojr script has a _health var declared. For me this was in the parent Enemy script, so it's inherited. For you, you can declare right there at the top of the script.
@@DashNothing I added var _health = 0 in my texture bar script and for good measure in my player script like you said but its still giving me null at the same lines hit_bar.value = health and max_value = health
@@DashNothing its giving invalid set index "value" (on base : "nil" ) with value of type "float" in the line hit_bar.value = health and the same is in the script init_health with max_value and value
@@DashNothing overall sry for spamming in comments but it works then I instatiate as child of my player but not when I instatiate to the overall world and now my hp bar is following player bcs its child of it how can I do that it works without adding it as a child of a player ?
@@Lutnar Oh that's a different story. Did you get the reference to hit_bar with @onready at the top of the script? If you have that line, make sure that the path to the health bar node is correct.
One thing that comes to mind is if you're using health that's over 100 you have to change both progress bars' max value property in the inspector to be more than that. Put a value that you know is bigger than you will ever use. Since they are set to 100 by default, they will just not show any difference for values greater than that.
Yes, you'd do it similarly to how the enemies health works for damage. For regen you update the healthbar's health value in the same way. The bar will fill up without leaving any of the white underlying bar visible. Also, it can follow the player aor be static on the screen like a boss healthbar, no problem.
@@DarknessSavior Maybe have a timer for the regen to kick off, and a var is_regenerating = false. Connect the regen timer timeout signal and set is_regenerating = true in the callback. In the _process() func check if is_regenerating and increase the health by a small amount, also updating the healthbar, as seen in the video. Check if health is already full, in which case set is_regenerating back to false. When the player takes damage you can call regen_timer.stop() to cancel any incoming regen, followed by regen_timer.start() to kick off a new attempt. This is just off the top of the dome piece. Try it and let me know how it went. Might make a video about this too.
I kinda made the health bar but I don't have anything to attach it too so it kinda doesn't work for me lol. I made the health bar deplete if I click my LMB but that's it lol. It doesn't even delete the health in a nice animated fashion lol. I still have lots of learning to do.
that was a great Simply explained, Speedy video. the thumb nail showed the bar with a different shape, wider at the start and narrow at the end, can that be implemented? I know Godot can have circular bars, but never seen wider to narrow.
This can't be done by only using the ProgressBar node. You would need to somehow make a mask that hides the progress bar in the shape you want. You would probably use a shader to get the masking effect on top of a sprite of the shape you want. It seems there's no built in way to mask nodes in Godot.
My health bar is initializing value and decreasing in value correctly but visually it doesn't change from the value set in the editor. How can I fix this?
This would happen if the progress bar's max value field in the editor is less than your health value. Max value by default is 100, so you won't see a change until your health goes below 100. You can go into the healthbar scene and crank up this max value to something huge that you know you're not gonna need to go over.
If you are using a setter for "health" and then change "health" inside the setter, wouldn't that result in recurssion? That's what is happening for me.
@@DashNothing I should have been more specific. I meant more in terms of if the enemy sprite changes (e.g., gets bigger or smaller) - how can you make sure the bar stays at the same relative height above the enemy
@@dodomoko If you put the sprite and the same healthbar under a common Node2D parent and then scale the parent instead, both will scale at the same time and remain proportional. This is the easiest solution, but the drawback is the proportions of the healthbar will not stay consistant with other healthbars (the border will be much thicker for example). Other solutions that come to mind: - animate the healthbar's position while you're animating the sprite scale (works only if you know the target scale in advance) - calculate the new healthbar position y by getting sprite.texture.get_size()..y * sprite.scale and set it in the process function or something Good luck bro!
5 місяців тому
Will this work also with TextureProgressBars? Or we need a different approach?
@@DashNothing Yea it works, but in the parent node i just deleted "under" texture and left only progress one, then in DamageBar changed progress texture from normal to white and it works exacly the same. Thanks a lot. :P
Hey man, I'm making my own game, and that health bar is cming in really handy for me,(Thank you so much!) but I don't have any enemy Sprites, do you have a recommened sprite, or atleast the ghost you used in your video?
You can search itch.io for free sprite packs, there's a lot of stuff on there. I also recommend, as do many other gamedev youtubers, Kenney's assets - www.kenney.nl/
You can have UI elements in 3D space by using a viewport texture on a plane mesh. There are tutorials for it if you search for terms like "godot UI in 3D" or "godot viewport texture". Hope that helps!
@@DashNothing will you doing it great... come on I'm just following you... and your channel is showing sign of good progress.. keep up the good work...
The enemy parent script has an on_dead callable which can optionally be assigned a function. Since the parent script takes care of deleting the scene when health reaches 0, it also calls on_dead first so any custom behaviour (like changing the sprite and emitting dust particles) which is defined in the child script, can happen first.
@@ULTRADARKSETH Thank you! Every enemy inherits from the Enemy.gd script which has the var health and a setter function _set_health. When you use the keyword super you're calling something on the base script, in this case the Enemy.gd. So this sets the health to a new value. You can also define var health inside of each enemy's script if you don't have a lot of them, which would make this code slightly easier to follow. But having a base class for the Enemy is useful when you plan on having a lot of different ones that each use the same set of vars (like health).
Why does the Health Bar not change color? extends Area2D var pMeteorEffect := preload("res://Meteor/MeteorEffect.tscn") var minSpeed: float = 20 var maxSpeed: float = 30 var minRotationRate: float = -20 var maxRotationRate: float = 20 @onready var healthbar = $Healthbar var health: int = 20 var speed: float = 0 var rotationRate: float = 0 var playerInArea: Player =null func _ready(): healthbar.init_health(health) speed = randf_range(minSpeed, maxSpeed) rotationRate = randf_range(minRotationRate, maxRotationRate)
func _process(delta): if playerInArea != null: playerInArea.damage(1)
I challenged myself to make this from my head without doing the tutorial and I did it! Lets g0000!
Lets go brother, good job!
Did you implement it in any different approach?
0:19 is where I'm commenting from.
At first, I would think that there would be two health bars overlaid.
The top bar moves down by percentage based on the hit.
The second would stay, and only move down if the top bar hasn't moved in some arbitrary length of time.
If the top bar value
Dot
The fact that you showed the general idea of the solution in the beginning (0:30) makes this tutorial S-tier in my book. ❤
Great tutorial, very helpful! Keep up the good work!
Thank you so much! I appreciate it dude!
Amazing tutorial, especially the fact that you use the Healthbar as a component. Too many people just add canvas layers or add a healthbar directly to their scene. Thank you!
Your tutorials are SO good!! Thank you for making them :)
Much appreciated!
I tried to implement this myself the last two days in my 3D isometric, but for the player health (tried to implement it into Camera script which I set as parent of the HealthBar). Thank you so much for this! Very nice and clear explanation, even though the part writing the actual script was a bit fast. Can't wait to get home and try it!
First time I watched a tutorial of his, I literally had the video on half speed during the script 😂
Bro this works wonders! You explained it so perfectly and it actually works! Also the way you set it up it can be used for multiple different things such as players and enemies! Thank you so much! Liked the video and subscribed!
It was super valuable, it opened up a logic in my mind that can be used in other types of systems, THANKS!
quick suggestion: instead of making the damage bar snap to the right value after the combo, you can use a tween to make it move towards the right value! so it's smoother
Nice, but I don't know how to make a tween, would it work with a ease function or something?
@@SleepyLazyPanda yea but tweens are way better, i suggest you look into them !
@@madeyslime ok thanks !
@@SleepyLazyPanda you're welcome !!
If you are making a fighting game, i would highly recommend to only change the damage indicator once a combo ends.
In case of someone that needs that, the way I did is the following:
1: Disconnect the timeout signal from the Timer of the HealthBar
2: Change the set_health function:
func _set_health(_new_health):
var previous_health = health
health = min(max_value, _new_health)
value = health
if health timer.time_left:
timer.disconnect("timeout", _on_timer_timeout)
timer.connect("timeout", _on_timer_timeout)
timer.start()
else:
damage_bar.value = health
Very cool tutorial! Saving this one and will use it soon! Thanks man
This is TOP quality tutorial🗣️
Thank you. A simple aspect of a game but the work into it. Ty.
I simply missing a simple piece of information that was left out of other tutorials I was looking at. Thanks.
Thank you so much for this bro. you explained it very well
I had an issue with the implementation because the health variable is assigned before setting the max_value and value variables. As a result, when the setter for the health variable is called during initialization, it used the wrong values for max_value and value.
To fix this, i simply set those two variables before i set health.
This should be standard in all video games because unlike numerical HP displays, a small damage is barely noticeable if displayed as a bar without a damage indicator where as numbers, you'll see the rightmost digit change (assuming no damage number shows) as numbers are very distinct visually than a bar.
At 5:25 I would recommend swapping the damage and health to represent the amount healed in the event that HP is greater than previousHP.
you can also spice up your healthbar by tweening it. It would look twice as better.
I just started learning Godot. This is helpful thank you 🌹
The init_health function will not work because we have changed the var health : set function.
In init_health the first two lines should be like this:
max_value = _health
health = _health
then it will work correctly.
You are a life-saver!
Found this too )
do you know why I'm getting null value on damage_bar in set_health function and same in init_health ?
I did one to one from video changed what you wrote and still nothing
If you get an error like this: “Attempted to call function 'init_health' in base 'null instance' on a null instance.”
Most likely you are trying to change values on a heatlhBar that has not yet passed _ready(). If you are trying to set the value of a heatlhBar, during the _init() of whoever owns it, move that to _ready().
If you just can't change the value, check again that you haven't made a mistake in the code. Check that you may have forgotten @onready somewhere.
Yeah, that'll be useful for later. Thanks!
Thanks, this was excellent, and I used it to make a 3D version that takes this and just makes a Sprite3D "Billboard" of it for my 3D game. I also put in a little tween as some have asked for so that the white part moves smoothly after the timer timeout.
my damage bar just becomes a giant box when i try to full rect anchor and I cant change the size
Let's godot is an amazing name. You go man!
do you have a video where you show the on_dead and super._set_health(value) parts in more detail? at the moment they're returning errors in my script
No, I wanted to leave the health / damage / death implementation up to the viewer so the healthbar doesn't depend on it. Any way you approach doing health will work with the health bar.
Here I used on_dead as a function defined in the parent Enemy script that can be overridden if needed. Also, var health is defined in the parent Enemy.gd so I call super._set_health() to trigger its setter first.
@@DashNothing thanks, is there any way you'd be willing to share your code for that section? I've just started game design and have found that putting together ideas from different videos/guides pretty tough.
@@ohhave3586 Here I made a gist with Enemy and BigGhost scripts:
gist.github.com/DashNothing/2a0a54397826b4f3aaeb7d90d9f01c73
@@DashNothing That's awesome, thank you so much!
Thanks my friend
Really cool tut, and I followed perfectly fine until I got to 6:38. You just already have this function set up for _set_health but obviously I wouldn't and don't have a function like that already set up. So where would I add the "healthbar.health = health" statement???
@@hrothgarnogar You update the healthbar's health any time your enemy's health changes.
In this case I have a var health on the enemy and a setter function _set_health which gets called every time you try to assign a new value to a variable. Here's a little example of setting up getters and setters: forum.godotengine.org/t/how-to-use-godot-4-setget/5975/2
Of course, you don't have to update healthbar's health inside a setter function. You can also do it when the enemy gets hurt, wherever that might be in your code. It's up to you.
@@DashNothing Super helpful thank you!!!
i get the error: Attempt to call function 'init_health' in base 'null instance' on a null instance.
This means you didn't get the reference to the healthbar node in your enemy script. Either you didin't add the healthbar to the scene, didn't write the @onready var healthbar = $... line, or the name of your healthbar node and what you're trying to get in the @onready line don't match.
Hope that helps!
@@DashNothing Month late, same issue as commenter above, but I've tried all of your fixes and it still is not working. Also says that health is not declared in the current scope but can that just be fixed by declaring health as a variable in the scene? I'm using it for my player character if that helps.
@@ponshop1742 Definitely add the health variable to your player script if that's where you're using the healthbar. Did you add the healthbar to the player scene? And did you use the instance scene button (chain icon)?
@@DashNothing Yep I've instanced the HealthBar scene into it, not sure why it isn't working
@@ponshop1742 The problem is your var healthbar is set to null because Godot couldn't find the healthbar in the scene. If the healthbar is in the scene also check if the spelling of the path to it is correct on the line @onready var healthbar = $...
To make sure you can delete the path and just drag and drop the healthbar from the scene tree into the code editor. This will generate a correct path to it.
thank you so much for the great tutorial. one question. in _set_health() (4:46), why do you write health = min (max_value, new_health) instead of just saying health = new_health? Does it make any difference?
@@ManuelAndreMusic Yes. The difference is you cannot set health above the max_value
@@DashNothing aaah thank you now I understand
@@DashNothing My personal challenge now is to implement a rally system with life regain - like in bloodborne
I really liek that knockback effect when the ghosts die from being shot. Would you be able to share how you did that?
thanks a lot g! this work very well on my code
I don't underatand what max_value is doing or why we need to use min() instead of just using new_health?
Edit: ok I think I get it, the _init_health parameter is passed in from the enemy script's _ready function. That means that the init_health function is only called once to set the max_value once, meanwhile newHealth changes each time var health is updated.
min(Max_value, new_health) prevents the value from exceeding whatever is initially define as the maximum health
Can anyone help me get hurtbox to work with lerp? I tried it myself but got an error, I'm a newbie and bad at coding, please help lol.
I'm getting null within init_health(_health) funtion in health bar and set_healthbar function getting null with damage_bar.value = health
any ideas what I did wrong, I did exactly 1 to 1 from video
@@Lutnar You have to make sure yojr script has a _health var declared. For me this was in the parent Enemy script, so it's inherited. For you, you can declare right there at the top of the script.
@@DashNothing I added var _health = 0 in my texture bar script and for good measure in my player script like you said but its still giving me null at the same lines
hit_bar.value = health
and
max_value = health
@@DashNothing its giving invalid set index "value" (on base : "nil" ) with value of type "float"
in the line hit_bar.value = health and the same is in the script init_health with max_value and value
@@DashNothing overall sry for spamming in comments but it works then I instatiate as child of my player but not when I instatiate to the overall world and now my hp bar is following player bcs its child of it
how can I do that it works without adding it as a child of a player ?
@@Lutnar Oh that's a different story. Did you get the reference to hit_bar with @onready at the top of the script? If you have that line, make sure that the path to the health bar node is correct.
was waiting for you to use lerp or tween to smooth out that transition :(
I planned on doing it, but upon closer inspection a lot of fighting games don't even do that, so I decided against it. Easy to add though.
I followed every step to the detail and the bar never updates I've been at this for 3 days.....
One thing that comes to mind is if you're using health that's over 100 you have to change both progress bars' max value property in the inspector to be more than that. Put a value that you know is bigger than you will ever use. Since they are set to 100 by default, they will just not show any difference for values greater than that.
@@DashNothing omg this fixed my problem, thanks!
Does anyone know if this can be done with a texture progress bar?
Hello bro, I need to know how your game is set up in Godot. Is there a way to download it? I want to test your configurations.
nice video brother
Wow. exactly what i need
Is there a way to use this for the player's healthbar, and set up automatic health regen?
Yes, you'd do it similarly to how the enemies health works for damage. For regen you update the healthbar's health value in the same way. The bar will fill up without leaving any of the white underlying bar visible.
Also, it can follow the player aor be static on the screen like a boss healthbar, no problem.
Could you give an example of how you'd code that?
@@DarknessSavior Maybe have a timer for the regen to kick off, and a var is_regenerating = false. Connect the regen timer timeout signal and set is_regenerating = true in the callback.
In the _process() func check if is_regenerating and increase the health by a small amount, also updating the healthbar, as seen in the video. Check if health is already full, in which case set is_regenerating back to false.
When the player takes damage you can call regen_timer.stop() to cancel any incoming regen, followed by regen_timer.start() to kick off a new attempt.
This is just off the top of the dome piece. Try it and let me know how it went.
Might make a video about this too.
I kinda made the health bar but I don't have anything to attach it too so it kinda doesn't work for me lol. I made the health bar deplete if I click my LMB but that's it lol. It doesn't even delete the health in a nice animated fashion lol. I still have lots of learning to do.
It's all a learning process. You'll get there bro
that was a great Simply explained, Speedy video.
the thumb nail showed the bar with a different shape, wider at the start and narrow at the end, can that be implemented?
I know Godot can have circular bars, but never seen wider to narrow.
This can't be done by only using the ProgressBar node. You would need to somehow make a mask that hides the progress bar in the shape you want. You would probably use a shader to get the masking effect on top of a sprite of the shape you want. It seems there's no built in way to mask nodes in Godot.
I bet shader is the way to go.
My health bar is initializing value and decreasing in value correctly but visually it doesn't change from the value set in the editor. How can I fix this?
This would happen if the progress bar's max value field in the editor is less than your health value. Max value by default is 100, so you won't see a change until your health goes below 100. You can go into the healthbar scene and crank up this max value to something huge that you know you're not gonna need to go over.
Help my health bar now lowering
thank you
If you are using a setter for "health" and then change "health" inside the setter, wouldn't that result in recurssion? That's what is happening for me.
@@JimKrillPDX No because in Godot you have to manually assign the value to the property inside the setter, otherwise it won't change
Any recommendations to make the healthbar float on top of the enemy instead of being static at the bottom of the screen?
5:50 is where I show it in the video
@@DashNothing I should have been more specific. I meant more in terms of if the enemy sprite changes (e.g., gets bigger or smaller) - how can you make sure the bar stays at the same relative height above the enemy
@@dodomoko If you put the sprite and the same healthbar under a common Node2D parent and then scale the parent instead, both will scale at the same time and remain proportional. This is the easiest solution, but the drawback is the proportions of the healthbar will not stay consistant with other healthbars (the border will be much thicker for example).
Other solutions that come to mind:
- animate the healthbar's position while you're animating the sprite scale (works only if you know the target scale in advance)
- calculate the new healthbar position y by getting sprite.texture.get_size()..y * sprite.scale and set it in the process function or something
Good luck bro!
Will this work also with TextureProgressBars? Or we need a different approach?
I haven't tried it, but I believe it will work the same.
@@DashNothing Yea it works, but in the parent node i just deleted "under" texture and left only progress one, then in DamageBar changed progress texture from normal to white and it works exacly the same. Thanks a lot. :P
Is it your mic picking up typing sound or some sort of software that adds it in post production? If it's the latter, what software is it?
@@mateuszparus It's MechaKeys
@@DashNothing thanks
Hey man, I'm making my own game, and that health bar is cming in really handy for me,(Thank you so much!) but I don't have any enemy Sprites, do you have a recommened sprite, or atleast the ghost you used in your video?
You can search itch.io for free sprite packs, there's a lot of stuff on there. I also recommend, as do many other gamedev youtubers, Kenney's assets - www.kenney.nl/
Awesome please explain how to make enemies in godot
"otherwise we are talking about"
- DashNothing
What is the health = 6 in function _ready():
@@farrell3488 Setting up the initial health value
Trying to figure out how to do this for a 3D game but sadly the same rules don't apply T_T
You can have UI elements in 3D space by using a viewport texture on a plane mesh. There are tutorials for it if you search for terms like "godot UI in 3D" or "godot viewport texture". Hope that helps!
Does this health bar work for player?
Yep, same principle regardless of what node uses it.
@@DashNothing thank you for answering
look cool
6:05
I saw what you did there
is there a way to add this to a 3d scene?
update, nvm i just learned it overlaps the 3d scene, dont need an answer thanks!
"_set_health()" not found in base CharactedBody2D
It's a function we define ourselves to be the setter for the health variable.
@@DashNothing oh alright :))
why you so good at godot engine?
It's just practice. Making stuff. And I'm still learning with you with every video I make.
@@DashNothing will you doing it great... come on I'm just following you... and your channel is showing sign of good progress.. keep up the good work...
What is the on_dead = die
The enemy parent script has an on_dead callable which can optionally be assigned a function. Since the parent script takes care of deleting the scene when health reaches 0, it also calls on_dead first so any custom behaviour (like changing the sprite and emitting dust particles) which is defined in the child script, can happen first.
Again. Very helpful ! Really flexible . I would like to know your ideas behind the enemies super._set_health(value) if you don't mind.
@@ULTRADARKSETH Thank you!
Every enemy inherits from the Enemy.gd script which has the var health and a setter function _set_health. When you use the keyword super you're calling something on the base script, in this case the Enemy.gd.
So this sets the health to a new value. You can also define var health inside of each enemy's script if you don't have a lot of them, which would make this code slightly easier to follow. But having a base class for the Enemy is useful when you plan on having a lot of different ones that each use the same set of vars (like health).
Why does the Health Bar not change color?
extends Area2D
var pMeteorEffect := preload("res://Meteor/MeteorEffect.tscn")
var minSpeed: float = 20
var maxSpeed: float = 30
var minRotationRate: float = -20
var maxRotationRate: float = 20
@onready var healthbar = $Healthbar
var health: int = 20
var speed: float = 0
var rotationRate: float = 0
var playerInArea: Player =null
func _ready():
healthbar.init_health(health)
speed = randf_range(minSpeed, maxSpeed)
rotationRate = randf_range(minRotationRate, maxRotationRate)
func _process(delta):
if playerInArea != null:
playerInArea.damage(1)
func _physics_process(delta):
rotation_degrees += rotationRate * delta
position.y += speed * delta
func damage(amount: int):
health -= amount
if health
In the code you posted where exactly are you attempting to change color? I don't see it.
@@DashNothing
Thanks, don't worry, I fixed it