Enemy takes multiple hits

Meanwhile it works that the player can shot an enemy and he explodes with an animation.
At the moment I try to made an enemy how can take multiple hits before he dies.

I tryed the object variable option. The only thing was changed is that the enemys are complete undestroyable. I can`t see any mistake. :frowning:

Can you describe exactly what you want to achieve or what does not work?

You have to do a system of variables. If the bullet collision with the enemy (trigger once), add 1 to the variable “Health” of enemy.
And another event, when object variable “Health” of enemy is x (the times you want the bullet to collision with the enemy before he dies) - and trigger once-, then eliminate enemy.

Blockquote
Can you describe exactly what you want to achieve or what does not work?

Oops, sorry.
Instead that the enemy dies after a few hits he is complete undestroyable. The kollision between the bullet and the spider works. But instead to disappear after a few hits he undestroyable `cause he tooks unlimited hits.

That was exact what I did. But it didn`t work. :frowning:

There is a “health” extension that’s prebuilt for this sort of thing, it may make it easier for you.

It’s included in the built in extension list, so just open that up and look for health. Search for New Extensions [GDevelop wiki]

Maybe the problem is the logic of your events. It would helpful if you show those events.

In your events you subtract -1 from the variable after Spinne is hit by the Bullet. Instead of -1 just enter 1.

2 Likes

I’m kind of blind but yes, i think it says -1. And that is not all, you have to add “trigger once” as a condition on those events. In that way, the event will consume less resources and you will prevent some troubles with how much time the bullet is colliding with the enemy (if you don’t use “trigger once”, that condition will get true every frame that the bullet is in collision with the enemy).

I would just do: at the start of the scene value of a variable is x. Oh and the numbers should be 1 not -1 and the death condition should be = 0 or </=0 (but if an attack can reach the negatives).Hope it helps😀 (</= is the below or equal to sign)

I’m not sure you need the trigger once, because as soon as a collision with the bullet is registered, the bullet is deleted. Having a trigger once means that if multiple bullets hit within a few frames of each other, only one of them registers.

Oh, that’s true.:thinking:

That was the solution. :slight_smile: My bad, sometimes I failed on the logical things.

@all:
Thanks a lot for the help.