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 ;)
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.
answered Jun 06 '14 at 03:20 PM
DizzyWes ♦♦ STAFF
Look at the objective system in the content examples, and try combining that with the health bar example. That should be all you need.
answered Jun 05 '14 at 07:06 PM
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
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here