I'm developing a game where the player changes states as their health decreases. Below 50, it should trigger animation1. Below 30, it should trigger animation2.
The problem is, I only want to trigger animation1 once. But my game timer is checking every "frame", so it's triggering animation1 every cycle below 50. I only want it to trigger once, then not again until it's gone over 50 and then naturally decreased back to below 50.
Are there any tried and true strategies for triggering state changes as a timer counts down (without the over-triggering problem)?
I thought I could say:
if (health == 50) animation1.play();
but sometimes, health never equals exactly 50, so it will skip right past that statement.