Designing enemy movement on a constrained lane

I want to create a system of enemy movement in only one direction, (in my case, constrained Z axis) but there are blocks that represent where they are. This is similar to Plants Vs Zombie. The enemies are unpredictable however and I want to allow sometimes for special effects like changing lanes and moving in reverse.

What’s a good way to design this system? Keep in mind that I have already made my own system on this but it would be helpful to see if there are better ways to go about this scripted system. The point of keeping track of the tile is for detecting collision if the tile has something so a better question is to probably try to detect if a tile is occupied based on where the mob is.

Any details I should mention to make it easier to understand are allowed as well.

EDIT: Maybe this is another way I can describe it?
While a moh is on a lane, get the exact square a mob is on while moving from constant variables rows R and columns C in the most efficient way while expecting the mob to attempt to complete the path even when unexpected situations occur such as being moved into a different row or pushed backwards. Mob’s goal is to reach the other side of which side they were initially starting from.

1 Like

You could lay out a couple parts equally and everytime you want to switch to that lane you just set your NPC’s Z position to that part’s Z position

That only describes lane switching. I also have to account that there are rows and columns, so each individual block can be occupied with something that prevents progress (collision) so I must always know what block they are on, I could represent this with an array where each table value has variables Row, Part (reference to Instance part), and Column.

1 Like