PathFinding.js icon indicating copy to clipboard operation
PathFinding.js copied to clipboard

Cannot set obstacles/unwalkable path using grid.setWalkableAt

Open hardyanto opened this issue 9 years ago • 3 comments

Hi, I am trying to set some obstacles on the grid by using grid.setWalkableAt. And I use raphaeljs to draw the path from the start to end point. However, it does not work and I don't receive any error. Can someone please tell me what is wrong with my code? Any help will be appreciated. Here is the zip file of my path finding project. hardy.zip

hardyanto avatar Jan 24 '17 06:01 hardyanto

you are first searching for the path on gridBackup, then setting non-walkable cells on grid. you need to set the non walkable cells in the first place and search for the path afterwards.

like this:

window.onload = function() {
  grid.setWalkableAt(3, 0, false);
  grid.setWalkableAt(5, 3, false);
  grid.setWalkableAt(5, 6, false);
  path = finder.findPath(0, 0, 10,0, grid);
  executeTask();
};

mfandl avatar Jan 24 '17 09:01 mfandl

hi, exactly at what point in time you can add non-walkable items in the code?.

Simus100 avatar Mar 28 '18 13:03 Simus100

Hi @simus100 , the non-walkable is checked when the path-finding algorithm of your choice checks the neighbors of the node it is currently visiting (see here ). After creating the grid before you run the path-finding algorithm should be safe and the preferred method but also during the iteration over the grid is possible if you squeeze your code in the beginning of the getNeighbors-function.

brean avatar Mar 28 '18 16:03 brean