Hi, today is my second day learning to code in Grodot, so I think I’m probably not doing this in the best way.
I set a hitbox for my player and my enemy, I have a bullet script and I use a set_health function to set the enemy’s health like this:
const Enemy = preload(“res://scenes/enemy.tscn”)
var enemy = Enemy.instantiate()
func _on_body_entered(body: Node2D) → void:
set_taking_damage(current_damage) # current_damage is a var that my gun script send to the bullet, so I can use the same bullet script for others guns
func set_health(damage):
if health <= 100:
health = health - damage
print(‘health inside if’, health)
else:
print(‘else’)
queue_free()
The problem is that every time I shoot, the enemy’s health stays at 70, since the bullet’s damage was set at 30, but the health doesn’t go down from that as it should, it always resets to 100 when another bullet hits the enemy.