how to make health system in godot 4.2
Im making 2d platformer game using godot. My player is made with node based state machine and health/damage is controlled by hitbox/hurtbox class. by using hitbox/hurtbox class, player will take damage as soon as enemy hit player and func player_in_hurt_state(amount: int):
is called by hurtbox class. This is fine if I want to make player to take damage instantly when hit by enemy or enemy projectile. However, im facing problem when I want to adjust the timing of when the player to take damage. for example, i want to make player to take damage not instantly but after transitioning to certain state, when hit by certain enemies. I tried to implement this, by calling player_in_hurt_state()
inside node state script. However, i get an error such as amount not declared or too few arguments, since state node have no idea what damage value is. For now, I made variable var player_take_damage = false
and decided to call true inside enemy script when I want to make player to take damage. But I feel this is little detour and dumb way. Is there any way to call player_in_hurt_state(amount: int)
inside state node script, or is there any other smarter way to do this?