playMaker

Author Topic: Health Bar GUI  (Read 4637 times)

Saputo

  • Full Member
  • ***
  • Posts: 107
Health Bar GUI
« 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.

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Health Bar GUI
« Reply #1 on: March 02, 2013, 07:55:10 AM »
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
Remember, you don't fail unless you give up trying to succeed!

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Health Bar GUI
« Reply #2 on: March 02, 2013, 08:01:13 AM »
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
Remember, you don't fail unless you give up trying to succeed!

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: Health Bar GUI
« Reply #3 on: March 02, 2013, 11:52:26 AM »
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

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Health Bar GUI
« Reply #4 on: March 03, 2013, 08:47:41 AM »
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
Remember, you don't fail unless you give up trying to succeed!

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Health Bar GUI
« Reply #5 on: March 04, 2013, 10:21:20 AM »
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
Remember, you don't fail unless you give up trying to succeed!

Saputo

  • Full Member
  • ***
  • Posts: 107
Re: Health Bar GUI
« Reply #6 on: March 07, 2013, 03:12:27 AM »
np, i had it too lasted a week sucked