I ask for your help. I couldn’t find a solution myself. Point:
When the scene starts, a random number of random enemies are created in a row along the right edge of the screen (600 on the x-axis and 100 on the y-axis in increments of 250 pixels, but maybe). There can be either 2 or 22 of them (enemies). And there are duplicates among them (identical, for example, 3 red and 2 blue).
After creation, they all move down by 250 pixels. When the bottom one reaches position 1075 on the y-axis, they stop. A random enemy is selected from all the enemies except the one in position 1075 on the y-axis, and its position is changed, moving it to the left side of the screen for 1 second before returning to its position in the row on the right.
Then, the unit at position 1075 is moved to the end. The cycle repeats.
The problem is that when 2 identical objects are created, such as 2 red enemies, and one of them is in position 1075, while the other is lower and its coordinate changes by 100 on the x-axis and 100 on the y-axis, after returning it to the row The loop doesn’t move on. I.e. the coordinate changes also and the object in position 1075. I attach a video for clarity, I’m sorry, it’s from my phone. When 3 different objects are created, the loop works well. But as soon as 2 or more are the same, it crashes, as you can see at the end (where there are 2 red opponents).
I don’t see a linked video. Can you post a screenshot of the events?
Instead of picking an object by an exact amount, you could use something like less than 150 or use pick nearest object. I like to use another object for the reference location.
Instead of
pick the nearest at 100,100
I would use
Pick the nearest at obj.X(), obj.Y()
You can use IDs but they can be difficult to maintain. It’s easier to pick objects based on location or if they’re in collision with another object.
Assigning IDs is fairly simple. Add an object variable like ID and then use another variable as a counter.
You can set the value of the ID as it’s created or use for each instance to number existing objects.
Instead of creating all of the objects ahead of time, you could spawn them as needed using a timer or other conditions. Then either move or delete the old objects.
I attached a video, but the website didn’t allow it.
I tried to link it to a coordinate, but unfortunately, it didn’t work either. However, all objects should be created simultaneously and then removed one by one.
If you don’t want to use YouTube, you could try the sites suggested here. I haven’t tried them. But if I ever need to post a video, I will. If you try it and find they work here, that would be great confirmation