easystarjs
easystarjs copied to clipboard
Walkable tile will break routing if not on startup grid but added later.
If you setup a grid were all tiles are 1 like [1,1,1,1,....], set tiles [1,2] as walkable and change the map during the game by setting one tile to 2 it will break the path finding. At first it will try to move around but if you keep recalculating the path it can't decide on one path and get stucked.
I am using the Phaser Plugin, I added a fix there: https://github.com/appsbu-de/phaser_plugin_pathfinding/pull/1
Maybe you like to add it to your setAcceptableTiles(), too.
I don't see how this is a problem with easystar. The collision grid and the acceptable tiles are independent variables, and so it shouldn't matter in what order you change them. Perhaps this was a problem specifiy to phaser_plugin_pathfinding?
This seems like an issue with the expectations around state. Maybe @PiNotEqual3 expects that easystar will track his changes to his collisionGrid without explicitly having to call setGrid
every time he updates it. It's an accidental side effect that this actually does kind of work. The part that doesn't work is the costMap
which doesn't get properly initialized if the grid is changed to include a new tile without calling setGrid
.
Maybe it makes sense to deep copy the grid passed into setGrid
. We would incur a performance cost, but it might save users from some nasty state issues like this one. I will have to think about this more.
I would suggest keeping easystar out of any state stuff, and require to call setGrid if you want to load a new grid (like a new level). For dynamic changes (like doors, bridges, etc) the avoid/stopAvoiding mechanism should suffice. Maybe it would help if this is documented a bit more clearly, with a unlockable door example.