I'll keep it short as possible. I often run into situations while using PM like this and always feel like I'm doing something wrong. I'm always thinking I'm not being efficient enough or my code is too sloppy. Here's an example I'm hoping you can look at. Let me know what kind of suggestions you have.
I have squares that spawn (using a spawn pool).
Each square starts on the right and moves to the left.
There are 65 Possible positions 5x13 grid.
I have an array list with every position on it called all positions
When a tile spawns on the right side I look through the array list of all positions for all the positions that match the spawned tile's row (in this case that is the Z axis)
All matching z axis are added to a new array list called possible positions
I iterate through the possible positions list taking the x (right to left value) from each vector 3 and adding it to a new list called possible positions x
now that I have an array with only floats I "array list sort" it and it puts the lowest value on top
Next, now that I have the lowest X value, I know which value is in the same row as the spawned tile, and of those, which is the furthest away.
I reassemble the y and z to my new found x, and use this vector 3 as my position to "move to".
I remove this vector 3 from the all position list, so the next tile that spawns in the same z (row) wont consider it.
This seems like such a long process to me, and I'm terrified that once I finish my game is going to be clunky