The player damage taking very quickly

The player’s health decreases very, very quickly due to collision detection; the system invokes the damage-taking function very rapidly. The question is, how can I control the player’s health so that it decreases gradually?

Because you respond to collision message, there will be many message while the bullet go through the player.
You can have a “hit timer” (state) you start when hit, and decrease to zero for some time, then you can be hit again.
Then you adjust the time to your gameplay.

Another way is to store the id of the bullet in a table ( bullets[id]=true), if the message is already in the array, you ignore the bullet.
So you are sure you count each bullet only once…but still you need some timer or way to delete the bullet from the table or the table will grow forever…maybe not the best way to handle it.

1 Like

I think that the engine reuses the IDs of the game objects due to the “object pooling” that happens behind the scenes( How to use object pooling? ) so the bullets table shouldn’t grow forever.

I don’t know if it’s a certain thing but In my case, the bullets table size is constant(around 20) after firing 1000s of bullets. The only thing to handle is setting bullets[id]=false after the collision is done.