Where do i store damage variables?

Hey, I’m very new to developing. So please go easy on me😁. I want to store a damage variable in the player that i can access through an enemy script. Something like:

if hurtbox entered:
health = health - player.damage

Is this the right way to do it?

1 Like

when you do hurtbox entered, it’s actually a body_entered(body) signal from Area2d Node
check if the body is player, then just

func _on_body_entered(body):
	if body is Player:

this is assuming your player has a class_name Player

to connect the signal body entered, easily right click the body entered signal here and connect, and press enter, it should create the _on_body_entered(body) function in your main enemy script

you can incorporate timer with timeout and boolean to re-hurt the player when the player is still inside the enemy hurtbox. but yeah, this is the most basic setup you can do. mind that this only hurt the player the moment the player entered the enemy hurtbox, player will still need to go out and get in the hurtbox to receive another damage. if you want it to do DOT damage or the player with invulnerability. then you have to setup more code for that

1 Like

It works! Thanks man. Godbless you

1 Like