Fix bug with diagonal movement (#174)
This commit is contained in:
+3
-4
@@ -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
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user