Fire Simulator and Health Bars

On our Fire Simulator game for Simulation and Serious Game Design there is one thing I would like to discuss in detail. That is a health bar, in our game used for the health of the players lungs.

The first step is to create your health variable being either integer or float, its up to you, on the character blueprint. I feel float is better in this case because you can make very small changes to it on an event tick for debugging and such. Compile your blueprint, and give that a starting value of 100. Now you can do whatever you would like with that health on your character however for the purposes of this demonstration you could simply have on event tick linked to setting the health variable with that set to a get the health minus an integer or a small float like .1. Keep in mind there are 60 ticks per second so if you leave it at one per tick, you'll go from 100 to 40 in a single second.

Next create a widget blueprint. Within the widget blueprint you only need to bring in a progress bar from the common section. To get a basic version going under the progress section percent can be 0.0, create a binding and the bar fill type is best in my opinion from left to right. Now under the graph, the binding you created which you can rename to something like Health Bar if you'd like. Within it get all actors of class, from the array pull out a get function. From the output of that get array pull out your health variable from the character. Take that variable and divide by 100. 100 being the maximum of the health.  Then send that value to the return value. Now you have a functioning health bar that will go down from 100% to 0% from right to left.


Popular Posts