[SOLVED] How do I kill a % of ennemies ?

0 favourites
  • 5 posts
  • Hi in mi game i have created an insane mode,where enemies are spawned every 0.3s

    what i would like is to kill a % of those spawned enemies, because if i keep playing the game start to lag due to the large amount of enemies.

    so at the moment i compared two values if enemies greater > than 350 = enemies destroyed, the problem is, they are all destroyed at the same time it is possible to destroy them by id or something to make them disappear one by one instead of all at the same time?

  • Hey again imothep85, :)

    There is a condition in the System object called "Pick Random Instance".

    You could use an event like:

    If enemy count is over 350, pick a random instance, and destroy that enemy.

    Remember, all your events only run once every tick (once every frame).

    So, this event will only destroy a maximum of 1 enemy per tick (per frame), and if you're creating enemies faster than that, they will still pile up.

    To make sure you always destroy enough enemies to get back to the limit, you can add the "For" loop condition, found in the System object. This will repeatedly trigger the same event several times in a row.

    Set the Start index to 1, and End index to the current count of enemies minus your limit (350).

    If you have 354 enemies, then the For loop will start at 1 and count up to 4, (350 - 354 = 4), re-triggering the even each step.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • An even better solution would be to not create a new enemy if there are already too many enemies on the layout.

  • Yes, dop2000 has a good suggestion there, and of the two solutions that's more elegant, as long as you don't need the enemies to spawn for some other reason.

    The main difference between blocking new enemies from spawning, and randomly culling excess enemies, is how the enemies will be distributed in the play area.

    Random culling

    If you randomly cull enemies, they will uniformly thin out as more are spawned, so that on average there will be a higher density near their spawn point and a lower density near the player, (which I assume they move towards).

    Hard Spawn Limit

    If you block new enemies from spawning, then a hole in the enemies will appear around the spawn point as they stop spawning, and the density of enemies near the player will stay unchanged.

    Feathered Spawn Limit

    There's also a sort of hybrid approach to limiting enemies, that might give you the best of both options, no culling of existing enemies, but with a smoother distribution of enemies.

    If you want enemy spawning to thin out as you approach 350, so that they don't just stop spawning abruptly, you can randomly "feather" off the spawn-success-rate of the enemies as you near the limit.

    For this you need a "soft" limit like 300, above which the thinning out begins

    When an enemy tries to spawn, it will always succeed if the count is under 300, but if the count is over 300, there's only a random chance it will succeed.

    This success chance will fade from 100% (when the count is exactly 300), down to 0% (when the count is 350).

    So for example, at 325, half way from the hard limit (350) to the soft limit (300), the chance of success would be 50%.

    at 340, which is 20% of the way from the hard limit (350) to the soft limit (300), the chance of success would be 20%.

    To do this, find the event that spawns the enemies, and try adding the following condition,

    Compare to general values (found in System object):

    random( 300 , 350 )

    is greater than

    Enemy.Count

    Now an enemy will only spawn if this random number between 300 and 350 is larger than the current enemy count. The larger the enemy count the less likely the random number will beat it.

    So, if the count is 325, the random( 300 , 350 ) has a 50/50 chance of beating it.

    If the count is 350, the random( 300 , 350 ) can never beat it.

  • Thanks so much to everyone :D solved with teh first solution pick a random instance if >350 destroy :D

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