easystarjs icon indicating copy to clipboard operation
easystarjs copied to clipboard

Walkable tile will break routing if not on startup grid but added later.

Open PiNotEqual3 opened this issue 11 years ago • 3 comments

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.

PiNotEqual3 avatar Feb 01 '14 08:02 PiNotEqual3

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?

sbj42 avatar Mar 26 '17 03:03 sbj42

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.

prettymuchbryce avatar Mar 31 '17 02:03 prettymuchbryce

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.

justusromijn avatar Oct 29 '18 15:10 justusromijn