(Solved) Enemy and Player health bar issue

I have made a single enemy spawn at a certain location. The enemy is created after the timer is greater than 1 seconds.
Now when created enemy is in collision with a object(it is not player) it decrease the player health.
Now the issue is that it decrease the player health only once(when the first created enemy touches the object, the rest enemy created donot decrease the player health).

Please post a screenshot of your events, when the enemies are created and when the collisions occurs

Health Bar of the player.
When enemy is in collision with the object.

The enemy created events are following,

Hi @Nikhil,

Try moving the “Triger Once” and Player health part under the P2 colliding with GO2, excample here:

Please note that I used states for my enemy, so you can disregard that part and also the timer :wink:

Let me know if this helped you out, and I’ll be happy to help if you need more assistance,

All the best and keep safe! :slight_smile:

Hi @Goku, I did it but it’s not solving the problem.

I notice that when the enemy is in contact with the object(G02) the player health is decrease by -5 only once and other enemy coming do not show any effect on player health.
But when the contact enemy is destroyed then the next coming enemy decrease the player health by -5, again the other enemies do not effect the player health.

I think the problem is that the GDevelop is considering all the created enemy as one single object. So it is only decreasing the player health only once.

What I should do that GDevelop consider all the created enemy as different object.

You need to add foreach enemies
foreach G02
— P1 is in collision with G02
----- Do things here

Like this

Sure but you’re only checking instances of P2 not each enemy try replacing P2 with G02 it’s because i guess P1,P2 are only uniques instances in the scene but could be multiple G02 right?

P1 is player.
P2 is enemy.
G02 is sprite.
Also P2 is being created multiple times.

Try setting the same object in the foreach if
foreach G02
– P1 is in collision with G02
---- Do things

I did but problem not solved.

Hi @Nikhil,

Again, the Triger once needs to be under the “for each”, and you can remove the empty event above Player Health variable, and move Stop enemy and change Player health under the for each as well, where triger once is.

In my example I have multiple enemies, like 3, that I multiplied, and then I added them to a group “Enemy”, and I then do for each enemy and it worked for me.

Sorry for a bad image, only had snipping tool, but you get the point :wink:

I did this,
Subtract 0.0625 from PlayerHealth when P2 is in collision with G02.
After this it looks somewhat better.

So did you manage to make it work for you ? :slight_smile:

Yes, now it works much better than before.

Glad to hear that :slight_smile:

Please could you change the headline and add [Solved], so this post will help others.