Having problems with enemy's health

Hello guys!!

I’m developing a little game in my spare time, it’s in a very early stage and i’m still making the health and attack system. But i’m having an issue with the enemy’s health system…

The print screen of my code is in the attachments, but here’s how i did it(logically):

1 - When the character(Guerreiro) is colliding with the enemy(Caveira) and the animation of the character is the attack one so it shoud apply a force to the enemy(Caveira) and add 1 to the enemy’s health variable(Life_caveira)

2 - When the health’s variable of the enemy(Life_caveira) is equal to 3 so it should delete de enemy from screen

That’s how i did it but when i attack the enemy the gdevelop just delete him instantly. I’ve noticed that when i press the attack button really quickly it doesn’t happen… My theory is that when i press the attack button the collision last so long that the enemy’s health variable is filled to the value i’ve set to the object to be deleted.

I don’t know how to solve this but i guess that must be a way that when i press the attack button it should act as only one collision for attack…

Can anyone help me?

Thank you guys!!

Yes, as you think the conditions “Attack animation = 2” + “Collision with enemy” is true for several frames, in each frame the damage will be increased, so the enemy will be deleted in 3 frames :slight_smile:

To fix it you can add a “Trigger once” aside the other 2 conditions, “Attack animation = 2” + “Collision with enemy” + “Trigger once”.
This way, the event will be launched only one time, but can be launched again if the animation switches to a different one than attacking, and switches to attack again (as you surely want), or if the enemy doesn’t collide and then collide again while the attack animation is playing (surely you don’t want it, but is very unlikely to happen if the attack is fast).

Thank you very much mannn!!

That’s just what i was looking for :smiley:

I’ve had to make a little modification at the code for the purpose of the game, but everything is working fine now :smiley:. I’m sending the print of the new code again, maybe it will help anyone in the future \o/.