playMaker

Author Topic: Health Bar Help  (Read 4480 times)

marcustegtmeier

  • Playmaker Newbie
  • *
  • Posts: 13
Health Bar Help
« on: April 15, 2015, 07:04:55 PM »
I'm trying to get my health bar working.  I've followed this tutorial until the scripting came into play: It seems really simple and would work great in playmaker.  I pretty much have everything set up except for the following:

  • 1. The character will take damage and health and it is reflected in the CurrentHealth global var but I'm not sure how to take that number and translate it in to movement of my HealthBar sprite.
  • 2. How can I set a minimum and maximum health (0-100 or something) so that the player can't receive or lose more or less health than that?

Here's an example of my health bar and how I would like it to work.


mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Health Bar Help
« Reply #1 on: April 15, 2015, 09:02:12 PM »
First make sure you have the Playmaker uGui actions-

The way to do it depends on if your health bar is a sprite(image) or if you are using a uGui slider element-

If the bar itself is a sprite then switch the type over to fill/horizontal and use the set property action to control its size

If its a slider use the set slider action to control its size

You can use clamp actions to set the minimum and max numbers

Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

marcustegtmeier

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Health Bar Help
« Reply #2 on: April 16, 2015, 03:26:23 PM »
mdotstrange, right now I have it set up as a sprite that has a mask component, I just need to get it to slide to the left or right as damage is taken and healed.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Health Bar Help
« Reply #3 on: April 16, 2015, 05:34:38 PM »
If you can't figure it out, here is a link to a really good one with playmaker support.   Energy bar toolkit.  Has everything you need and is simple to use in playmaker.

https://www.assetstore.unity3d.com/en/#!/content/7515

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: Health Bar Help
« Reply #4 on: April 16, 2015, 09:06:39 PM »
I recommend what wheretheidivides suggested, I am using it in my current project for iOS, and it's great. You can even do a couple effects like a burn out effect like in old fighting games, where if the bar subtracts health/energy it leaves a separate bar behind it which slowly reduces its amount until it catches up.
Most Recent Published Games:
Juicy Theater - Android

marcustegtmeier

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Health Bar Help
« Reply #5 on: April 16, 2015, 11:31:25 PM »
Thanks for the suggestion wheretheidivides and serene fox, but I think I'd rather save the $25 bucks and figure it out myself, it's more meaningful that way. 

There has to be some kind of action out there that will translate a float var to a vector to allow movement along the x axis right?

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: Health Bar Help
« Reply #6 on: April 17, 2015, 02:40:24 AM »
Are you trying to animate the mask you have to move from left to right or vice vera?  If so I would look at https://hutonggames.fogbugz.com/default.asp?W674 This action or the regular "animate float" might be what you are looking for. Then while you have that working have the same float variable in this action https://hutonggames.fogbugz.com/default.asp?W379 (or the Vector2 equivalent) on the X axis every frame.

As for the health stopping at 0 and above max I would set a condition to where if it hits zero "do something" or if it goes above max, clamp it by using the "float compare" action. Where if its ever greater than say 100 health reset it to 100. So if the player picks up health and it goes to maybe 110, set it to 100 again.

Not too sure if this would work but I wouldn't know unless I see it in front of me.


I would at least suggest one of the GUI systems if you aren't using one already.
Most Recent Published Games:
Juicy Theater - Android