Godot Version
4
Question
Hello, I’m trying to do a damage system for my game. When a player moves into a “bad tile”, it calls the signal on the player hurtbox, takes away a life point and makes it invincible for 1.5 seconds. The thing is, I’m trying to figure out how to make the player take damage again if after the invincibility period they’re still placed in a bad tile. I tried doing it in _process(delta) but no matter what conditional I put, the process takes away all the health and bugs the game. Here is the code:
func _process(delta):
if in_dmg_area && !invincible:
health -= 1
invincible = true
inv.visible = true
after_damage_timer.start()
if health == 0:
inv.visible = false
timer.stop()
$AnimatedSprite2D.play("Death")
can_move = false
func _on_player_hurtbox_body_entered(body):
in_dmg_area = true
if body.name == "BadTiles" && !invincible:
$HurtSound.play()
$HitEffect.play("Hit")
health -= 1
set_health()
invincible = true
inv.visible = true
after_damage_timer.start()
if(health < 1):
var lost = lost_game_scn.instantiate()
stats_viewport.add_child(lost)
lost.connect("restart", _restart_game)
func _on_player_hurtbox_body_exited(body):
in_dmg_area = false
func _on_after_dmg_inv_timeout():
invincible = false
inv.visible = false
func set_health():
match health:
0:
life_heart_01.set_frame(11)
life_heart_02.set_frame(11)
life_heart_03.set_frame(11)
1:
life_heart_01.set_frame(0)
life_heart_02.set_frame(11)
life_heart_03.set_frame(11)
2:
life_heart_01.set_frame(0)
life_heart_02.set_frame(0)
life_heart_03.set_frame(11)
3:
life_heart_01.set_frame(0)
life_heart_02.set_frame(0)
life_heart_03.set_frame(0)