PathFinding.js
PathFinding.js copied to clipboard
Pathfinding with blockable finish cell
For example, I have the matrix like:
[
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]
So, if i will try to find the path from 0, 2
-> 4, 2
it will be smth like [[0, 2], [1, 2], [2, 1], [3, 2], [4, 2]]
. It is okay. But let's imagine that 2, 2
is some loot, which can't be walked through untill it will be picked up, so I want have the possibility to move to unwalkable 2, 2
cell, if it is the final cell like:
0, 2
-> 2, 2
= [[0, 2], [1, 2], [2, 2]]
.
What I will do is backup and modify data of that cell to walkable, do the search, and recover that data. Unless you are using matrix data concurrently (hell, this is JS), there should be not problem. The other notable issue of this method is, if you target is surrounded four sides but not diagonally, the path to access it diagonally won't be found (unless you use DiagonalMovement.Always
, which is not used by default). But it is probably irrelevant to your need.