why do 3 health bar appear for 1 monster?

0 favourites
  • 4 posts
From the Asset Store
Health, Weapon & Rage Bars for your Games. Easy to use & Customize.
  • Hi guys

    I'm trying to create health bars for enemies in this learning project, however, I'm encountering a problem.

    When the health bar reaches 0, the enemy should do its dying animation and get destroyed, however this is not happening, and I think I have narrowed the cause the the fact that somehow there are 3 health bars attached to the monster, instead of one. The issue is that I don't know why there are 3 health bars, I have attached a screenshot below for you guys to check, as I've wasted more than an hour myself trying to understand what is going on.

    On monster created, I have a sub event with a for each loop and a trigger once condition for creating the health bar above the monster sprite. As a separate event, I set the position of the health bar to the monster's position, and set its width as the HP variable from the monster. When the health bar reaches 0 (or below), it is destroyed.

    I have also set a state for the monster stops the platform behaviour, sets the "Explode" animation, upon its finish. the monster sprite is destroyed. This is then tied to a condition below where it is actioned when the monster HP is less or equal than 0 (as damage received can take the HP into the negative).

    As in the screenshot attached, I don't see where the other health bars are coming from. The all have the same position (I clicked on them in the debug page).

    https://i.imgur.com/myD1FsO.gif

    Can someone please explain what am I doing wrong here?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First get rid of the loop, it should be on monster created, create health bar. The on created condition picks the monster that was created. Check if that sorts it..

    Also the set position logic is a bit off because it doesnt pick a monster. You can try linking the bar and monster with unique IDs, or a better way is to use a container. This puts the health bar and monster together in a group so when you create the monster, it creates the health bar (no need for any create logic then) and also when you pick health bar to set position to monster they are then related/linked in the form of a container.

    Also if you pin the bar to the monster on creation then it's easier to control than set position every tick.

    Your final logic using a container would be something like :

    Monster on created : set bar to required monster position, pin bar to monster.

  • Your solution worked like a charm, thanks very much! I have added the Pin behaviour to the health bar and added both monster and health bar in a container.

    I have tried to do the For Each loop, as I want to try to make a wave system for the monsters, so I thought this would work best when I spawn a number of different type of monsters in a wave.

    Your solution should work also because, as I understand this, I attach the health bar on creation of the sprite, so as long as they are in a container, doesn't matter how many I spawn, they will each have their own health bar.

    Thanks again!

  • Yes exactly, you do not need to use a for each loop, the event handles itself. On created relates to the one being created at the time so it will work for any new monster.

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