I have run into a problem calculating attacks.
If the player is attacking and an object intersects his attack hit box, I call the damage() function of the object.
Problem is, this happens every loop, and the object is damaged several times during a single attack animation.
I searched the forums for a solution, but I didn’t find anything. My ideas:
I thought I might end the attack after causing damage once, but that makes cleaving attacks impossible.
- I thought of “tagging” the enemy as damaged, and testing for this before applying more damage, but I would have to reset each object between attack animations.
- My best idea is to use a timer, allowing damage() to be called only so often, so there is a recovery period after being attacked, during which the object cannot take damage. Problem is, the recovery period cannot be shorter than the animation. If it is too short, the attack will still hit multiple times. If it is too long, the next attack might not cause damage. I don’t want to use a set animation length. Maybe I can pass the animation length to the object when it is damaged…
Any thoughts? How do you handle this kind of attack?