Hi everyone!
I’m working through the Godot 3D course and am stuck on the Health and Labels lesson for Barbarian Blaster. I think I have everything set up correctly, but when I test my game, the Base loses health to quickly and the game resets in less than a second. Any ideas why this might be happening? Code below:
base.gd:
extends Node3D
@export var max_health: int = 5
var current_health: int:
set(health_in):
current_health = health_in
print(“health was changed”)
$Label.text = str(current_health)
if current_health < 1:
get_tree().reload_current_scene()
@onready var label: Label = $Label
func _ready() → void:
$Label.text = str(max_health)
func take_damage() → void:
print(“damage delt to base!”)
current_health -= 1
enemy.gd:
extends PathFollow3D
@export var speed: float = 2.5
@onready var base = get_tree().get_first_node_in_group(“base”)
func _process(delta: float) → void:
progress += delta * speed
if progress_ratio == 1.0:
base.take_damage()