Fix bug with diagonal movement (#174)

This commit is contained in:
Jonathan Calvert
2022-03-01 13:28:01 +00:00
committed by GitHub
parent bbfce2bb77
commit 1d477094b8
+3 -4
View File
@@ -56,7 +56,6 @@ export function findPath(from, to, token, previousWaypoints) {
} }
function getNode(pos, token, initialize=true) { 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) if (!cachedNodes)
cachedNodes = new Array(gridHeight); cachedNodes = new Array(gridHeight);
if (!cachedNodes[pos.y]) if (!cachedNodes[pos.y])
@@ -101,9 +100,9 @@ function calculatePath(from, to, token, previousWaypoints) {
nextNodes.pushWithPriority( nextNodes.pushWithPriority(
{ {
node: getNode({...to, layer: startLayer}, token), node: getNode(to, token),
cost: 0, cost: startCost,
estimated: estimateCost(to, from), estimated: startCost + estimateCost(to, from),
previous: null previous: null
} }
); );