Track multiple enemies health?

0 favourites
  • 9 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • Hello,

    I was following an excellent tutorial by Ayzhong 1945 Tutorial Part 6

    and ran into an issue. In his tutorial he is explaining how to make a 1945 clone, and had us create two different enemies. One was a basic one hit plane, and the other was a 5 health Submarine. Whenever there are more than one plane enemy on the screen, and you kill it, the others do not die.

    However with the submarine, which has an "instance variable" of 5, they will sometimes all die together when you kill one, or sometimes they do not.

    If you need me to upload the capx let me know. Otherwise any suggestions would be appreciated.

    Thanks. <img src="smileys/smiley1.gif" border="0" align="middle">

  • This is one of the main issues of Construct 2, and I hope it will be solved with better support to IIDs and UIDs, as said here: http://www.scirra.com/forum/suggestion-show-i-uids-for-selected-objects_topic55109_post344056.html#344056

    So, you'll ran in two type of problems, and all the answers are "bad" in my personal opinion.

    Or you create the enemies and keep tracking them with UID or IID, so, you can manipulate their health as well, but when you destroy one of them, you'll modify the index and flush their UIDs or IIDs.

    The second method is keep them invisible after their health goes 0. This will improve the number of objects on the canvas, but will not reset the UIDs and IIDs.

    I personally did a workaround for it by this way:

    When the player shot on an enemy and hit him, set the to drop the health of the nearest enemy of that projectile. It's working nice, but when two enemies are hit by the projectile, it only drop the health of the nearest.

    So, I'll improve the code to check the overlapping enemies, so, if the enemy is overlapped, drop his health.

    This is working because one thing Ashley said on his Manual here: scirra.com/tutorials/37/beginners-guide-to-construct-2/page-6

    So, if you create a new enemy, the engine will treat this enemy as a unique object (UID and IID), but you can know where it is and manipulate him by making a conditional meeting your necessity, so, when the bullet hit the monster, that specific monster, inside that conditional, will lose health or die. ^^

    A long and terrible explanation, but I hope it's understandably!

  • It is a little overwhelming at first glance, but I will dive into this deeply tonight. Thanks to your two workarounds I will see what I can come up with.

    Thank you! =)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you should upload the cap file, ill take a look at it, it might be simpler than that

  • I don't understand - instance variables are perfect for things like health. They are kept independently for each instance, and an event like "If health < 0, destroy sprite" will individually destroy sprites which run out of health, and never affect all of them at once.

    Are you sure there isn't a mistake in the tutorial, or a mistake in your events?

  • There is a mistake in the events. Its a picking issue like I expected.

    You need to have the ACTION that subtracts from the health variable directly connected the the CONDITION of the bullet hitting the submarine. That way the game knows exactly which submarine to subtract health from, the submarine that is colliding with the bullet. As it stands now, the game doesn't exactly know which submarine you are referring to, so when any submarine is hit, they all lose some health. Those two have to be tied together.

  • Ahh ok , thank you very much. =)

  • I don't understand - instance variables are perfect for things like health. They are kept independently for each instance, and an event like "If health < 0, destroy sprite" will individually destroy sprites which run out of health, and never affect all of them at once.

    Are you sure there isn't a mistake in the tutorial, or a mistake in your events?

    That's it what I tried to say boss:

    o, if you create a new enemy, the engine will treat this enemy as a unique object (UID and IID), but you can know where it is and manipulate him by making a conditional meeting your necessity, so, when the bullet hit the monster, that specific monster, inside that conditional, will lose health or die. ^^

    I mean this is a treat when you have, for example, a rocket with smoke, where the smoke is attached to the rocket.

    To explain this topic, you can set individual instance variables for each smoke and each rocket, when creating them. Mean "instances" as "index numbers stored as variables".

    When the rocket is destroyed, make sure to destroy the smoke with the same index number as the destroyed rocket.

    How to set instances: Instances CAPX

    Live sample: Instances HTML5

    And all without UID and IID, you really don't need to care about them. They are very much volatile ^^

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