I have one HP bar for each enemy. How do I make them reduce one at a time instead of all at once?

0 favourites
  • 4 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • I've been googling for the past 20 minutes to no avail. Here's my project file: ufile.io/21yo4

    The problem code is in the eHealthbar event sheet. The variable "prevHP" is only for the health bar system, feel free to remove it while messing around.

    Right now, each character in the Character family has a HP bar. They're pinned correctly, and they all get destroyed correctly when one character dies. I also have a working formula on how to reduce the size of the HP bar according to player HP.

    The problem I have is that every enemy takes damage at once. How do I make it so that the only HP bar that is reduced belongs to the enemy that was attacked?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • there are to many events in your game, can't wrap my head what goes where since there is no comments inside, but the logic should be

    if character is hit, subtract N from character.self_HP then set character healthbar to character.self_hp/character.maxhp *N.. as you did.

    in order to get the healthbar of that character u have to have a unique identifier can be a instance variable on the character and healthbar having same value, so if u spawn lets say a 10th character u give that variable value 10 and the healthbar instance variable would be 10 also. you can also use the newly created character system UID and save it in the newly created healthbar. but that might cause issues depending on how you use it.

    then u pick the healthbar that has instance variable identifier = to character instance variable identifier that gets hit.

    Edited: here is an example i made for you explaining the above multiple-enemies-healthbars.c3p

  • Thanks for the project. It's too late for me to fix my project tonight, but I'll study yours tomorrow.

  • How about a simple instance variable on a health bar. And it starts at 100, each time a character is hit, deduct damage from his health bar instance variable, and you also set its health bar size to whatever the value is ( in the beginning its width will be 100 then just scales down to remaining value after each hit. )

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)