0 votes

For my enemy code:
var maxhp= 10
var current
hp
currenthp= maxhp
Func Onhit(damage):
currenthp -=damage
If current
hp <=0
dead()
Else:
$AnimationSprite.play("hurt")

My player code:
var damage
Func Area2dbodyentered(body):
If body.isingroup("enemies")
body.Onhit(damage)
Func physicsprocess(delta):
If event.Input.isactionjust_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

in Projects by (29 points)

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.

1 Answer

0 votes

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

by (29 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories