Properly checking distance for changing parents of already processed nodes.

This commit is contained in:
2024-06-05 04:14:29 +02:00
parent d3d7a0013f
commit 9f3af7b380

View File

@@ -268,13 +268,11 @@ Variant MultilevelAStarEx::find_path(const Vector2i &from, const Vector2i &to, b
node->open(_pass, current, current->distanceFromStart + distance, to2);
open.push_back(node);
}
else if (node->state(_pass) == Node::OPEN)
// TODO: check if this should only be performed on open nodes or all nodes
else if (current->distanceFromStart + distance < node->distanceFromStart)
{
if (current->distanceFromStart < node->parent->distanceFromStart)
{
node->parent = current;
node->distanceFromStart = current->distanceFromStart + distance;
}
node->parent = current;
node->distanceFromStart = current->distanceFromStart + distance;
}
// find the closest cell