How do I destroy 5 random objects?

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello everyone.

    So I'm making a casual mobile game, the enemies come from the outside of the layout toward the center (where the character is) and you should destroy them by tapping them. I have a power up that destroys 5 random enemies at once, so I used "pick random instance of an object" (I put it in a repeat loop to be repeated for 5 times), the problem is sometimes it destroys 2 enemy, sometimes 1, sometimes 0 (but mostly 5) and it obviously shouldn't be like this. any solutions?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Create a variable that count number of destroy enemy.

    If variable < 5 -> pick random enemy.

    On Enemy Destroyed -> Add 1 to variable.

    Then reset variable to 0 if you want to reuse.

  • Couple of other methods:

    System For Each enemy Order by random(1)
    System compare two values Loopindex<5
    	: Enemy destroy
    
    Repeat 5 times
     Enemy is visible
     Pick random Enemy
    	: Enemy set invisible
    	: Enemy destroy
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)