Working health counter

Godot 4.2.2

So i’m wondering is there a simple way to make a health counter or something like that I already have a working health system with my code now i’m wondering Is there a way to have a counter in game to see my health while im playing I know this is possible but everything I tried hasn’t worked

im fairly new to Godot I know all the main functions and can write simple pieces of code with gdscript but this isn’t anything I have ever come across

my health code is

extends Node2D

var take_damage = false
var health = 3

func _on_area_entered(_area: Area2D):
take_damage = true
if take_damage == true:
health -= 1
print(health)
if health == 0:
get_tree().quit()

Yep! There is a dedicated node for this: the ProgressBar. You can set it’s value (see Range for details) and min and max values to get a smooth bar for health. If you want a little more, you can use a TextureProgressBar with the same techniques.

If you just want a number, use a Label node.

Either way, you can set its value/text (depending on node type) every frame or every few frames and when every they take damage to the current health value.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.