I ran into another problem I'd like to share. I'm not 100% sure that the fix will work for all cases, but I think it is a good place to start.
At some point near the end of an NPC's path, the movement code will notice that there is LOS to the destination with no hazards. This is independent of the culling code. There are timers that periodically check for this situation, and abandon the calculated route when possible.
This works great. However I've seen cases where the pathing code will travel direct for a bit, and then calculate a new route to a nearby path node. The NPC wanders off, and then comes back to the destination. Sometimes this route recalculation has occurred more than once.
I'll advance the argument that once a safe direct path is found, that FindRoute should never be used again. Let the NPC head straight towards its destination.
When this direct path is selected, the Route list is cleared. Code later notices an empty route and tries to calculate a new one.
The following change has corrected this in my tests:
Code:
@@ -1059,6 +1059,13 @@ VERTEX Mob::UpdatePath(float ToX, float ToY, float ToZ, float S
return To;
}
}
+
+ // do not recalculate route once a direct path is selected
+ if ((Route.size() == 0) && (PathingTraversedNodes > 0) && (SameDestination))
+ {
+ return To;
+ }
+
mlog(PATHING__DEBUG, " Calculating new route to target.");
Route = zone->pathing->FindRoute(From, To);
The check on Route.size will be true if a route has been cleared, or if
a route has never been calculated. The PathingTraversedNodes check
rules out the later case. The "return To" directs the NPC to head directly
to its destination.