The damage that i made to the enemies does not stack how do i fix it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Regret666

For my enemy code:
var max_hp= 10
var current_hp
current_hp= max_hp
Func Onhit(damage):
current_hp -=damage
If current_hp <=0
dead()
Else:
$AnimationSprite.play(“hurt”)

My player code:
var damage
Func Area2d_body_entered(body):
If body.is_in_group(“enemies”)
body.Onhit(damage)
Func _physics_process(delta):
If event.Input.is_action_just_pressed(“melee”):
damage=5
$Animationplayer.play(“attack”)

The end result is that the first damage is only counted like 10-5 = 5 and the current_hp will always stay on 5

I have a question about this method you use, can you enlighten me how exactly you communicated the damage from the player to the enemy?
You only used a signal to check in the body entered the area… and a group for checking if the body was the enemy… did the body.onHit go through the group?
I didn’t get that part.
Thanks.

Parescop | 2021-04-01 04:19

:bust_in_silhouette: Reply From: Regret666

I just need to put currenthp=maxhp in func _ready()