Fix bug with pathfinding when previous node is not null

This commit is contained in:
glax 2024-07-23 04:04:11 +02:00
parent 3a1ca0cc3d
commit f8b3d72292

View File

@ -92,7 +92,7 @@ namespace astar
return PathFound(graph, neighborNode, currentNodeEnd, logger); return PathFound(graph, neighborNode, currentNodeEnd, logger);
float distance = (currentNodeStart.Distance??float.MaxValue) + (float)currentNodeStart.DistanceTo(neighborNode); float distance = (currentNodeStart.Distance??float.MaxValue) + (float)currentNodeStart.DistanceTo(neighborNode);
if (neighborNode.PreviousIsFromStart is null || neighborNode.Distance > distance && currentNodeEnd.PreviousNodeId != neighborId) if (neighborNode.PreviousNodeId is null || neighborNode.Distance > distance)
{ {
neighborNode.PreviousNodeId = currentNodeEndId; neighborNode.PreviousNodeId = currentNodeEndId;
neighborNode.Distance = distance; neighborNode.Distance = distance;