Hitting/Scoping Multiple Enemies in a loop

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hello again folks.

    I've had a good run of coding a scrolling beat 'em up recently. Each enemy is at present made up of a collision box to test their movement and hits, sprites to show animations, and shadows for their floor positions, I create these pieces at the start of the frame for each enemy, run a loop to assign them IDs, then another to sync them all together - so far so good, I've been able to successfully scope these pieces individually when attacking and knocking down each enemy using this method.

    Please login to see this attachment.

    My issue however is that so far, this only works when attacking one enemy at a time. I've been using the 'only one action when event loops' feature on striking an enemy, as this stops their values going over where I want them and the sound fx going crazy, the problem is that when hitting several enemies at once, such as with this explosion, only one of them reacts to it, and if I remove the 'one action' limiter only one gets hit and falls correctly, but the other goes crazy and locks up?

    What would be recommended to address such an event, where more than one enemy is struck at a time, and how to make each of them react appropriately?

  • I'm trying it with collisions rather than overlap but it's very twitchy, sometimes it knocks them both down, other times it knocks one down correctly whilst the second one glitches, and others it misses the second one completely?

  • Look into For Each loops. I think they're better suited to your needs. They may seem a bit fiddly to set up at first, but they're pretty straightforward really. As the name suggests, they'll let you apply actions for each enemy that has collided, ensuring that each is scoped properly. Here's an example. I've also included an alternative to the only one action when event loops method.

    When the grey object collides with one or more red ones, the for each loop will rotate them each in turn. The event #8374 will run for as many red objects as have been hit, one by one, and will correctly scope a single red object each time it runs (a fastloop would not have such precise scoping). A group containing a sound action will also be opened, and will play as soon as the for each loops have finished (and will close itself immediately afterwards). No matter how many enemies you hit at once, the thud sound will only play once per game frame, rather than once per enemy, which as you know can get deafening.


    Please login to see this picture.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

    Edited 3 times, last by Volnaiskra (December 12, 2022 at 10:14 AM).

  • Thanks for the tip Volnaiskra, I think I'm finally starting to get the hang of 'for each' loops now, but hadn't considered activating/deactivating groups to make certain events more precise, I'll keep it in mind

  • Okay, so I've had some success applying the tips given in this thread, but have sadly ran into another problem

    For the past few weeks I've been working on coding the hit mechanics for a single enemy, and recently decided to start adding another. I've got the code set up to spawn each of them individually at the start of the frame along with their respective parts ie collision boxes, shadows, attack range sensors etc, and both enemies I've placed into the same object groups so as I don't have to completely redo the code for each.

    Now here's the problem. When I have duplicates of the same enemy in the frame, everything works fine, they scope individually and register the hits as I want, this is true for both enemy types. The problem is when BOTH types are present, neither reacts to anything I do?

    I'll gladly go into more detail if required, but I thought this might be a common error with a simple fix, if anyone can help me out?

    Hope you all had a good Christmas btw :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!