Enermy health bar



  • How can I make so that each enermy when is spawn has a health bar above it (or can be invisible) so that if I use spawn object it won't die in one hit or have a set amount of hits till it dies. Basically each enermy has a health bar that decends depending on which attack you use



  • Give the enemy a Health Attribute and put them in a tag, make them spawn a health bar when they spawn. Make the health bar not scenery at first (so that it can collide with the enemy), collided with enemy group activates get Health attribute of that group and get position of that group, also turn on a timer that has both the get attribute and get position connected to it, then just add a few other behaviours under the timer only, like move to point get position (or you might like to add a value to the Y position so that it is above the enemy) and set health bar to the attribute. Probably also should set health bar to scenery when that's done. I'm not sure if there's a better way, but that's how I do it, if it's too hard to understand I can try to make some screenshots. EDIT: this does not work as health bars aren't allowed to collide.



  • @Aidan-Oxley I don't get this. Can you show an example?



  • Hmm I'm gonna have to think of another way, health bars aren't allowed to collide. This might end up being fairly complex, instead of showing screenshots I'll post an example to the hub when I'm done (and add another comment in forums to say it's done).



  • @Aidan-Oxley It doesn't really have to be health bars above thir heads. I just wanted a way so that each enermy has it's own health but I just thought that health bars might look cool



  • Yeah it would look cool, I am gonna make it work (nearly done already). I've never made a game myself with hovering health bars above spawned objects.



  • It's done, but I might need to add a few comments and stuff in to make it easier to understand, I will upload it in less than or about 3 hours from now (I'm about to go out, won't be able to use my iPad for a bit).



  • @DGames135 This is knew of those things that should be simple but sadly isn't, because there is no way to select a spawned object without using collisions. The workaround is to use dynamic attributes on a non-spawned object to transfer information between the spawned objects, using an ID to specify which. Here is an example project.

    For example, to get the health of the object with ID 2 you would get the attribute "2 Health". It's an inefficient way to do it and I hope Aidan has a better way, but this is all I can think of. With my method you'd probably want to avoid having more than 6 health bars.

    Alternatively, if you don't want visible health bars, you could just use an attribute in the enemy called health, and when it gets hit, subtract from that, if it's less than 0 kill it, but this doesn't look as nice.



  • @Jack8680 that's pretty much how I did it, will upload to hub soon



  • It's on the hub now.



  • @Aidan-Oxley Omg thanks. Didn't have time to check it but I will



  • @Aidan-Oxley Ok I checked it and I kinda get it. The thing I got is that you have to give each enermy and health bar a id but the rest of the spawning mechanisms I don't get. Also the combining text is confusing.



  • @DGames135 If you can't figure it out, you can just try to copy it behaviour for behaviour. All the combine text does is combines the words Xposition, Yposition or Health with its ID, all the spawning does is adds 1 to the ID attribute then spawns an enemy and a health bar to go with it.