Javascript 查找路径避免软碰撞

Javascript 查找路径避免软碰撞,javascript,path,dashboard,path-finding,Javascript,Path,Dashboard,Path Finding,我有x,y仪表板10x10。我有一个目的地x,y的数组,我需要从中找到最近的和它的路径 我还有软碰撞数组和pernament碰撞数组 我正在使用路径查找包查找路径。我正在设置pernament碰撞,如下所示: //set collisions for(let i = 0; i < mapData.collisions.length; i++) { grid.setWalkableAt(mapData.collisions[i].x, mapData.collisions[i].y,

我有x,y仪表板10x10。我有一个目的地x,y的数组,我需要从中找到最近的和它的路径

我还有软碰撞数组和pernament碰撞数组

我正在使用路径查找包查找路径。我正在设置pernament碰撞,如下所示:

//set collisions
for(let i = 0; i < mapData.collisions.length; i++) {
    grid.setWalkableAt(mapData.collisions[i].x, mapData.collisions[i].y, false);
}
我找到了最接近的坐标和它的路径,就像这样:

//find actual closest coordinate and its path
for(let i = 0; i < destinationCoords.length; i++) {
    currentGrid = grid.clone();
    currentPath = finder.findPath(heroCoords.x, heroCoords.y, destinationCoords[i].x, destinationCoords[i].y, currentGrid);

    if(currentPath && currentPath.length !== 0 && currentPath.length < closestPathLength) {
        closestPathLength = currentPath.length;
        closestPath = currentPath;
        closestCoords = destinationCoords[i];
    }
}
现在的问题是,如果我有以下仪表板:

其中黄色是起点,绿色是终点,粉色是软碰撞,它只会穿过粉色瓷砖

但我想要实现的是避免软碰撞。因此,路径应该是:

但当没有其他选择时,路径将是:


有什么想法吗?

看起来合适的策略应该是两次跑两次传球:

1将永久碰撞和软碰撞标记为不可通行

2如果没有解决方案,则仅将永久碰撞标记为不可通行


如果仍然没有解决方案,那就没有可走的路。

嗯,我不知道为什么我没有想到这一点。谢谢,我会努力的,如果一切顺利,我会记下这个答案