What is the best way to handle taking damage?

Hi there,

I am looking for the best way to take damage. The collision system I am using is as so:
Take a 64x64 object - Add 4 small rectangles, 1 on each side. Create methods in each object class to where if one rectangle intersects another objects rectangle (specified side on both), do something.

I am NOT looking to change my collision system, but more for the best way to add damage to a player.

Because, at the moment… when the player collides, it just subtracts health the entire time they are touching, rather than just once on the next one. I may add it so that the player gets knocked back or something…

Thanks!

Sounds like either knock back, start a countdown timer when they collide which ignores collisions until its zero. Or use a flag which disables checking untill the 2 objects have moved away

Maintain a list for every projectile that you use to store the entities that have already been hit.
When the projectile finds a collision check if the entity is on the list, if it is then just ignore it. :slight_smile:

I recommend LiquidNitrogen’s fix rather than Panda’s - it would be much easier for you to implement, and might even be a little quicker. Assuming everything that can be hit damage is extended from a base class (like Entity or something), give Entity 2 floats - currentInvincibilityTimer and invincibilityTime. You can set these to whatever you like in the subclasses, so you can make different things invincible for different lengths of time after they’ve been hit.

Yea, that is what I’m considering. The only problem is that my code is becoming super messy. It sucks! I have about 3000-5000 lines so far.