I have a small puzzle where a token moves down a board each time you click a button. The buttons you have to push are direction buttons that control which way all of the enemies on the board move.
right now i’m running it on a loop where each enemy looks for an open space and moves in the direction corresponding to the button pushed. My problem that i can’t seem to fix is that when the enemies line up in numerical order, the enemy at the end of the chain is the only one that moves. meaning, that the first enemy in the array sees the next one in the array in the spot it wants to move to. it doesn’t move because an enemy is already there. but the one on the end has an open spot next to it so he moves just fine. what do i need to do get get everyone moving in unison?
the enemies find the next spot by doing a sphere cast and moving to the collided location marker in the direction. the enemies themselves block the spots to move to.
edit: also, i can’t just run the array backwards due to the enemies being able to line up out of order. and that results in some enemies moving twice.
Try sorting the array of enemies by their location before running the loop.
For instance, if you want to move right, sort the array so that the right-most enemies were the first in the array, and the left-most — the last.
However, it might be tricky to do in blueprints. In C++ it is possible to sort an array depending on a certain value, but blueprints don’t give you such an option, unfortunately, so you might have to write a custom sorting function.
So the problem is, that the target location is currently blocked, but it would be free until the Enemy theoretically arrive at that spot, because the other enemy, that currently blocks it, will also move in that same phase, right?
Then i would introduce a variable “IsMoving” or “WillBeMoving”, or something like that, and whenever an enemy finds another unit blocking it´s target location (where it wants to travel), then it can check for this variable, to see, if this unit also has the intention to move, or if it will staying at this place. Then you could initialize the movement despite the spot currently being blocked, because that variable tells it, that it is moving away.
Oh, maybe check for that others guy target location or direction/heading too, just to see, if they would collide midtravel and block each other. Or to initialize an evasive maneuver.