Problem with lives and collision

Basically, when the character, which is the bee, touches the plants with teeth, they are supposed to lose a life. However, whenever my bee flies through it or touches it, all the lives are gone. I am also having the same problem for the wasps in the game. For the wasp, I arranged the collision mask on it’s stinger, but the same thing happens.
Any suggestions? I am quite stuck.


This is the code:

Hi,

your collision events need a “Trigger once while true” condition. Otherwise the collision is checked once per frame resulting in the immediate loss of all the health points.

Btw you could put all the enemies (wasp, beehive etc.) in an object group and use this for checking the collision with the Honeybee. This reduces the number of event blocks and you can just add more enemies to the group without changing your events later.

I assume you want there to be a delay where the player can’t be hurt for a second, but will get hurt again if they stay in collision too long. Trigger once will not work for this, as the player will not get hurt again unless they fully move away from the enemy and then collide again.

What you could do instead is create an “invincible” state for the bee. This could be a variable or timer that starts counting down when you get hurt. In the check for collision, also add a condition to check that the bee is not invincible (timer is still going, countdown variable > 0, etc).

If you’re using the Health point and damage extension, there’s already the function for damage cooldowns.

Thanks, although where should I put the condition?

Can you please write the code? Because i am trying to visualize what it should look like. Thanks

Actually, nevermind, I found where to put it, also it works, thanks

1 Like

I tried the trigger once condition and it worked but it won’t hurt to try out your idea

I’ll write pseudo-code :stuck_out_tongue: (pseudo-events?)

beginning of scene                  |     reset & start timer "noHurt" on Bee
---------------------------------------------------------------------
Bee is in collision with Enemy      |     subtract life
timer "noHurt" of Bee is paused     |     reset & start timer "noHurt"
---------------------------------------------------------------------
timer "noHurt" of Bee > 2 seconds   |     pause timer "noHurt"

The timer could be either a scene timer, or an object timer. In this case I think an object timer makes more sense but whichever you use, just make sure to keep it consistent (otherwise you’ll end up with two different timers and things will break)

thanks a lot! :grin:
had to write this sentence you are reading right now because the last sentence was shorter than 20 characters :woman_shrugging:

1 Like