Help with the For Each Object: Repeat (SOLVED)

Hi all! How can I make each of the newly created sprites follow the moving hitboxes? I’ve been trying to think of a way and I saw the FOR EACH OBJECT: REPEAT function but I’m no programmer and it’s making my nose bleed for a few hours now trying to figure out how to make it work. :frowning: I’m trying to make enemies appear in patterns similar to Shoot Em Up group enemies, you get the idea.

Purple boxes are just hitboxes that move from right to left and the yellow diamond is supposed to be the enemy but somehow it just follows the last hitbox spawned from the right.

I don’t know how to use the function properly as well.

Here’s the project file as well if you want to take a look.

I would be really thankful for some help!

The problem is the event 5, it iterates over each EnemyBox, but moves every Enemy to it, because there is no condition to choose a specific Enemy.
I’ve fixed it, in two ways:

  • WIth an ID variable, after creating an EnemyBox and an Enemy, “link” them with the same (unique) ID variable, then, iterate over each EnemyBox as you do but move the Enemy with the same ID.
  • With the extension to link objects, after creating the objects, link them, then move the Enemy linked to the current EnemyBox in the For each loop.

Both versions are here:
My project (13 KB)
To make the things clear, I’ve merged the two events that looks pretty similar (3 and 4).
De/activate each version to confirm both of them work :slight_smile:

If you alter the third action in event 4 to be:

Add to EnemyBox a force, angle: 90+Random(90) degrees and length: 200+Random(50) pixels

then you get a jiggling cluster of objects, which is quite a nice effect and shows how the enemy and enemy hitbox are now linked.

WOW! I’m just blown away with how easily you solved the problem with just two simple methods, with I could do that. :smiley: Thanks a whole bunch for answering my questions, appreciate it a lot!

Now I can relax with the options you gave me. I tried looking for tutorials about Variable IDs on the Wiki and Google but couldn’t find one, only the Child Variables have topics. And the AND/OR statements look so much cleaner and more professional now that you fixed them! One last thing though, I tried using the Path Behavior on the Enemy sprite and changed the Path Position (X,Y) to the EnemyBox position but it didn’t give the desired result of enemies moving up and down (Sine movement) but rather it gave some interesting results. Is there a Sine behavior or function I’m not aware of? :slight_smile:

Nice! It’s a cool and trippy action and would be very useful for my insect or zombie enemies. Thanks a lot! :slight_smile:

It may not be useful for your game, but I’ve just noticed that if you set the damping on the force applied to enemybox to a non-zero value (e.g. 0.05) it turns the spawn object into rather a good missile launcher.