Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Saputo on March 02, 2013, 12:11:56 AM
-
How would I go about making a Health bar that does down when u get hurt by the right amount, and fills up over time, just in the gui part? if u have to toss in the How to do this while making it work as well then go for it. I'm clueless on how to do this.
-
Hi! I'm fumbling around with my own game right now, and i guess i can explain how i made mine :)
First i made a jpeg file of how i want my healthbar to look (in my case just a bright red square bar)
I then changed the color of it to a darker red and saved it again so i had 2 files (a bright red and a dark red)
I then imported it to the scene of the game (the bright red first), set the width to 200 (make height whatever you want) and added an FSM to it.
first state has a simple wait function that waits for .1 seconds before going to the 2nd state (this is too avoid errors of trying to calculate health before the health has been set)
in the 2nd state, I use float operators to calculate the length of the bar based on the health of the player.
I assume you have a variable set for the max amount of health your player can have (in my example i used 300) and then another variable that tracks the CURRENT health of your player (so that could be 150)
first take a float operator and take the current health var and divide it by the max health var - store the result of this as "health divide result" variable.
now 2nd action, use another float operator - this time take the "health divide result" var and multiply it by 200 (width of health bar), and save the result as a variable called "health bar length"
As the last action, use the "Set GUI texture pixel inset size" action, and as the width, use your "health bar length" variable, and height whatever you want. Now make all of these actions update "every frame" by checking the "every frame" checkbox and it should now update it's width to match your health :)
for the dark red, i put that at the same location as the bright red, but put it BEHIND. This means that when the bright red health bar goes down, you can see the dark red behind it so you can see how much health you are missing.
This healthbar will also work if you have items that increase max health or something like that :)
Hope this helps, if you have any questions feel free to ask and i can try and help (i could make a video explaining my setup)
KozTheBoss
-
oh, and for the regen over time, you could make an empty gameobject and call it "health regen" or something
add an FSM to it, and make 1 state.
In this 1 state, use a "float add" action (assuming your current health variable is a float)
and make it add .5 to the "current health" float, and check the "every frame" checkbox.. this will make it regen .5 health every frame - change as needed
alternately you can also use the "per second" checkbox instead of every frame
-
Thanks great post, I video would be really helpful to myself and others i'm sure, and would I be able to add this to a system like a Stamina Bar you press Left Shift and it goes down over time, once it runs out u can no longer run, and it goes back to the walk set up?? that's my main goal for this
-
yes that is deffinitely doable, im doing something similar with health regen anyway - i will look into making a video explaining my setup :) hold tight, it might be up tomorrow
-
Hey man, i've fallen ill with a horrible flu so i won't be making a video right now - sorry!
I hope you figure it out from my first post :)
Koztheboss
-
np, i had it too lasted a week sucked