I have a bit of a problem with my movement and I am not sure it is solvable at all…
I have player and enemies moving on a grid and I want them to not move into each other. I can’t use physical colliders, since they then would stop somewhere and not on distinct grid points. I can’t use raycasting, since they all move at the same time, so when there is a empty tile between two objects and they both want to go there, raycasting would allow it. I have tried using an array to set specific tiles invalid when occupied, but that somehow doesn’t work during runtime (probably because I coded it wrongly) and suffers the same problem as raycasting anyway.
Anyone here has an idea, or am I screwed?
Well, you could do it in a two-pass way- every object sets the tile it wants to move to as 'occupied', and then the engine checks for whether any given object is allowed to move, given the one-step-forward occupation status! Just out of interest, if two objects want to move to the same grid location, how does it determine which one gets to go first? I don't quite understand how this works, given that they 'all move at the same time'.
– syclamothAlthough they move at the same time, I doubt the engine calculates it at the same time for both objects, so whoever is calculated first, has priority, with the player having priority over all enemies. How would I do this? Store all destinations in an array and then compare each to every subsequent one and recalculate (or stop) the ones that are the same? Wouldn't that take quite some time to calculate?
– Piflik