/// <summary> /// Returns the node with the smallest distance to goal. /// </summary> private SearchNode FindBestNode(CollisionBody collisionBody) { SearchNode currentTile = openList[0]; float smallestDistanceToGoal = float.MaxValue; // Find the closest node to the goal. for (int i = 0; i < openList.Count; i++) { if (openList[i].DistanceToGoal < smallestDistanceToGoal && !collisionBody.Collides(openList[i].CollisionArea)) { currentTile = openList[i]; smallestDistanceToGoal = currentTile.DistanceToGoal; } } return(currentTile); }