Fix one-way wall collision detection (fixes #167) (#172)

This commit is contained in:
Jonathan Calvert
2022-02-28 18:13:12 +00:00
committed by GitHub
parent b227d5073b
commit 8d243ce919
+2 -2
View File
@@ -42,7 +42,7 @@ export function findPath(from, to, token, previousWaypoints) {
let currentNode = lastNode; let currentNode = lastNode;
while (currentNode) { while (currentNode) {
// TODO Check if the distance doesn't change // TODO Check if the distance doesn't change
if (path.length >= 2 && !stepCollidesWithWall(currentNode.node, path[path.length - 2], token)) if (path.length >= 2 && !stepCollidesWithWall(path[path.length - 2], currentNode.node, token))
// Replace last waypoint if the current waypoint leads to a valid path // Replace last waypoint if the current waypoint leads to a valid path
path[path.length - 1] = {x: currentNode.node.x, y: currentNode.node.y}; path[path.length - 1] = {x: currentNode.node.x, y: currentNode.node.y};
else else
@@ -74,7 +74,7 @@ function getNode(pos, token, initialize=true) {
} }
// TODO Work with pixels instead of grid locations // TODO Work with pixels instead of grid locations
if (!stepCollidesWithWall(pos, neighborPos, token)) { if (!stepCollidesWithWall(neighborPos, pos, token)) {
const isDiagonal = node.x !== neighborPos.x && node.y !== neighborPos.y && canvas.grid.type === CONST.GRID_TYPES.SQUARE; const isDiagonal = node.x !== neighborPos.x && node.y !== neighborPos.y && canvas.grid.type === CONST.GRID_TYPES.SQUARE;
let targetLayer = pos.layer; let targetLayer = pos.layer;
if (use5105 && isDiagonal) if (use5105 && isDiagonal)