How do I create an 2D Enemy Health Bar?

Ive played with a the HUD a little lately so ive played material instances and 2D vectors but…

Could someone walk me through setting up a health bar for enemy class bps??
When they receive damage the nar pops up 2D I assume facing the player and depletes like on the HUD.
Thats what I need…

If anyone can walk mt through that its be splendid. Thanks :wink:

Hello,

Have you taken a look at the Content Examples and the HUD map, there’s a health bar in that example. There’s also a couple threads on AnswerHub and the forums that may help you, HERE and HERE. As for the actual Health system, there’s a post HERE too.

More documentation will also be coming soon regarding the Content Example and how the HUD was set up.

-W

Well the health bar was going to be floating above the enemy…instead of being on the HUD.

Look at the objective system in the content examples, and try combining that with the health bar example. That should be all you need.

Here’s a very quick and dirty example one could take:

Add two boxes to your character, one box for health the other for max health (e.g. a green box and a black box).

I’m not sure if you want this for a player character or an enemy, but this should get you started.

Scale the health box based on your damage system (for testing, I just hooked it up to F key press to scale it).

The Blueprint shrinks the bar by .1 then moves the bar along the Y so that it lines up with the Max Health bar behind it.

While there is much more to do with this (branching to see if health is at 0, hooking it up to a damage system as I said, tweaking the amount the bar scales, etc.)… this might give you some ideas.

-W

That was excellent! ! Thanks a million. :slight_smile:

This is fantastic. I am currently using this method. Just a question though, is there a way to make the material change once it has reached a certain size? so like if its 50% it goes Yellow and then 20% Red?

YES!

I just got done working on something myself. Personally, I prefer to use a billboard, but the same logic applies. We’re still working with the Y scale. Scale the bar however you feel - In my example, I’ve used 96. Keep that number in mind.

You’ll also need to declare some basic variables.

  1. Healthbarfullscale - Basically getting the default “96”
  2. HP Increment - the value we’re feeding into our billboards Y axis to scale it.

You need 3 Materials.

  1. OK Health
  2. Medium Health
  3. Bad Health

20837-materials.png

On begin - You’re going to want to reference that Y scales initial value.

While I’m testing, I find it’s useful to print strings as visual feedback to make sure I’m pulling the right value through.

Then, on take damage - add a sequence. Damage mechanics go in first. Then, you rescale your bar.

This works by getting your current monster HP as a percentage of the full HP, and scaling the Y axis by that factor. The value returned is fed back into the element. So at 67% health, your bar will be 67% of that initial “96” that you got.

Once you’ve scaled, the third step is to see if we need to give visual feedback about the condition. Basically I can split 96 into 3 segments. 0-32, 33-64 and 65 to 96 - nice 32/32/32 chunks.

I check first if I’ve gone below 65. If I have, I then check if I’m below 33. If I’m not below 33, I go yellow, if I am, I go red. If I’m still over 65, then I do nothing, and stay at my default.

Once we’ve built this, let’s look back.

Key things -

I always set the scale before the colour. You’ll notice the scale element draws the same material on “make” that it pulled from “break” - essentially - “I will always use whatever colour my bar is set to, until I need to change it”.

My Float/50 - My initial monster HP is 50 in this example. Current HP/50 returns a factor of 1. This is the easiest way to scale, as you can then just use this as a multiplier.

This bar scales inward from both ends.

You can apply the same logic as the original answer to mitigate if you want. Kick it along the Y axis transform by using a product of your multiplier, and the current bar Y scale to come up with a value to feed into the transform.

Easy Peasy.

Hi,

With the latest version (4.5), you can do that by using UMG (Unreal Motion Graphic) ;). It’s pretty simple to use. There’s tutorial you can check.

is this in 4.5? or 4.6? im runnin 4.5.1 and cant seem to find how to attach the umg to the char.

In 4.6.1, you can just attach a widget to the Actor. Tesla has a nice video that steps through it – I’ve tried it myself and it works perfectly :slight_smile:

https://www.youtube.com/watch?v=M7w9OfPRpKM

You’d replace the mesh, I’d assume.

You can change the color by binding the ‘Fill Color and Opacity’ to a function. Feed the health/percent into it and do your logic in there. That will output green to yellow to red, etc.

A easier way would be to drag in your box, and do a check based on how scaled it is, and use the set material node to change its color

can you share how you would do this?