How do I kill an instants of an enemy

0 favourites
  • 4 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported
  • Hi all, I am excited to learn about Construct, and start playing around with it.

    So, I created a simple game: when the game start I generate an enemy and a player

    The enemy then will start attacking the player.

    When player click on the enemy, it reduce the enemy's health.

    And when the health reduce to 0 the enemy or player die.

    That work fine.

    Then I add a random function to generate between 1 to 3 enemies. (This the problem)

    No matter how many enemies pops out on the screen, they only behave like one enemy.

    They attack the same amount of damage to the player

    When player click on one enemy, other enemies health also get hit.

    I saw few videos on youtube, and did not see any specific function on even sheet, but the enemies seem to be working independently. Please advice.

    Thank you in advance.

  • So there are a few different ways to go about this. One way is to nest your enemy's code under a "for each" loop. That may be unnecessary if you use functions and instance variables to determine how your enemies act.

    As an example of what I mean by my second point, you can do something like:

    -If Enemy health =0 -> Call function "Kill enemy" (add a parameter with enemy.UID - the UID is a unique identifying number that belongs only to that instance of teh enemy object)

    -On function "Kill enemy"

    ---Enemy - Pick by UID(function.param(0)) (this is picking the enemy instance using the UID you added to the parameters of the function. In this case it is parameter 0 because it is the first parameter) -> Enemy -> destroy

  • Thanks ultrafop.

    I am following your advice using UID. On the debug, the enemy had UID, and IID. I am not sure how they number of UID generated(ubt it does not matter if you set the UID into a veriable). However the IID, is like an array, start with 0 to how many instants.

    I understand the concept, but still little fuzzy on technical. On your example you use parameter, which is make sense, but I am not that that advance. It is possible to set enemy.UID into a global varibale, or a enemy.UIDS variable? Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instance variables are what you need. Each enemy can have their own instance variables, in which you can store each one's health, attack randomiser, AI state, anything you want.

    https://www.scirra.com/manual/73/instance-variables

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