![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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