From 1d477094b81b9a34295f33f4916cec4f6304a010 Mon Sep 17 00:00:00 2001 From: Jonathan Calvert <38069151+JDCalvert@users.noreply.github.com> Date: Tue, 1 Mar 2022 13:28:01 +0000 Subject: [PATCH] Fix bug with diagonal movement (#174) --- js/pathfinding.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/pathfinding.js b/js/pathfinding.js index 17e8601..d361c93 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -56,7 +56,6 @@ export function findPath(from, to, token, previousWaypoints) { } function getNode(pos, token, initialize=true) { - pos = {layer: 0, ...pos}; // Copy pos and set pos.layer to the default value if it's unset if (!cachedNodes) cachedNodes = new Array(gridHeight); if (!cachedNodes[pos.y]) @@ -101,9 +100,9 @@ function calculatePath(from, to, token, previousWaypoints) { nextNodes.pushWithPriority( { - node: getNode({...to, layer: startLayer}, token), - cost: 0, - estimated: estimateCost(to, from), + node: getNode(to, token), + cost: startCost, + estimated: startCost + estimateCost(to, from), previous: null } );