how to constrain a health bar to zero over time?
Approw
Member Posts: 703
I want the health bar to decrease its "width" (and the speed that its decreasing) over time during the gameplay. The player can add health though, so interpolate did not work for me. any solutions?
Thanks!
Comments
Hey @Approw,
Interpolate won't work properly for a number of reasons. What you need to do is constrain the health bar width to a number. I will try and help explain it here and hopefully it will make sense.
Lets say you want it to reach 0 after 60 seconds. (Change according to what you want)
Next we need to determine what the max length of the health bar will be. For my example I will say the length will be 450 pixels.
Now go into the health bar actor:
How I got the 7.5?
So the maximum health time allowed is 60 second, so 450 / 60 = 7.5. We used 450 because that is the width of the time bar we determined we wanted. If you wanted your time bar to be 250 just do 250 / 60 = 4.16. Then you would replace the 7.5 with 4.16, etc.
Then in an actor in the scene, have a rule that says;
Have the next following rules (these are to be on the safe side just in case)
Change game.health time to 60 (or what ever number you need for your game that you used above)
When game.health time is less than 0
I believe that is everything. Hopefully this works out for you and one last thing.
When restarting your game, level, new scene, or anything along those lines, change game. health time back to 60 (or what ever number you need for your game that you used above)
@KillerPenguinStudios Thanks for your reply! does this method make the health bar decrease smoothly? because I had something working, but it jumped to the width instead of a smooth animation. I hope you can understand what I'm trying to say haha. thanks