StarCraft health bars

Hey yalls I have little dude units that walk behind walls and I need my little dude units to show me their health bars even when behind such aforementioned walls which obscure the camera.

My initial idea is to have all their little health bars be on an overlay scene and then just copy the position of the little dude’s but I may be over thinking it.

Any ideas before I do way too much work on a sub par idea?

That’s the way I do it. You need to get their screen position, I have a script for that some where, and then you can use the same code as for placing a custom cursor.

The key to making a really flexible system is to use a erase and redraw cycle along with a list, so that you start the frame by erasing all the health bars, then get a list of all agents, find which ones are on screen (their screen position is not more than 1.0 or less than 0.0 in either axis) and then place new healthbars, setting their value as you do so. Erasing and adding objects each frame is slightly more costly than just having a dozen objects already on screen and making the unused ones invisible, but it is much more flexible and total overhead is never more than about 0.5% on my system.

If you want to do it the other way get a list of healthbar objects in the overlay at run time, get a list of agents on screen, do a for i in range (max number of health bars) and set agent[i] with healthbar[i], pass if you either run out of agents or run out of healthbars. If there are more healthbars than agents you should make the remaining ones invisible or move them off screen.

This is also an excellent way of doing a radar or mini map. In addition I use it for getting debug info about the AI, giving each agent a short string description about what they are doing right now and then using a text object in the overlay to display it.

It’s actually a slightly complex system, with a lot of requirements but when you get it working it looks very professional and has lots of potential applications such as targeting info about an enemy unit.

I found this tutorial that explains how to do a basic one but I don’t know how you would do a fancier one like with Zelda and the like where you have hearts and the disappear and reappear in portions, that’s something I’ll be looking into myself.

Oh and wait a minute, if you’re talking about positioning couldn’t you just parent an empty on the top of their heads and work from that?

hi Skormeus,

I think using an overlay could work but it looks overkill for health bars.

I suggest you to set z-offset = 10000 on the material of your health bar and parent it on top of the head of your “little dude”
Properties -> Material -> Options
It will draw the health bar on top of the wall even if the object is behind if you set hight enough z-offset. This trick is similar to x-ray option in blender viewport

Then you should make the heath bar face the camera. Once again you can try Properties -> Material -> game settings -> face orientation = Billboard but I’m not sure it will fit your needs.

There are other solutions but at lease this one avoid any python logic to be run.

Let me know what do you think

Nice tip glender.
Never used z-offset property before nor knew what it actually does but it works nicely.

Btw: Does anyone know why it is grayed out no matter what?

Smokin_mirror: I figured it would be something like that. I’ll have to brush up on the specifics but thanks mate. Probably the best way to go and explaining it like the custom mouse cursor thing makes sense.

Glender: That’s a very interesting solution I’ve never even heard of. I’ll mess with that :slight_smile:

So it’s not actually the health bar part I’m having trouble with. It’s having them track to the units and be visible even when structures or other units would be in the way so the parent technique isn’t strong because they are a part of the geometry of the scene and will then get obscured by other geometry. But thanks for the timely heads up :slight_smile:

With the hearts thing you might have to use a bit of scripting but in essence could do the X hearts split into four pieces and have each piece turn invisible one by one every time you get struck.

Maybe not the most elegant way but how I’d do it to stat if on a time crunch. Best of luck mate

You have to turn on transparency for that material.
It could be an interesting idea, I’ve never tried it before now either.

Holy cow Glender that was so easy I don’t know what to say. You are exactly why I posted this before writing a page of code to get the same effect :confused:

smoking_mirror > thank you for the precision, I used it without transparency activated :slight_smile:

skormeus > I’ll be glad to see the result in your game

Sorry to bump a solved thread, but thanks so much for this. It’s a super useful trick for any Blender user, and it lets me layer my comicbook “Boosh! Bam! Slam!” effects above everything. Thank you!