(ee3387a0d) Attempted fix for bots occasionally getting stuck between nodes and reversing to a previous node. Only replace the previous path when the cost of it is lower than the current path's cost (or if the target is not at the same place/ not yet assigned). Didn't have enough time to test, not sure if it works.

This commit is contained in:
Joonas Rikkonen
2019-05-18 17:23:13 +03:00
parent f4ed2ed217
commit d5594ee591

View File

@@ -144,8 +144,9 @@ namespace Barotrauma
protected override Vector2 DoSteeringSeek(Vector2 target, float weight)
{
bool isDifferentTarget = Vector2.DistanceSquared(target, currentTarget) > 1;
//find a new path if one hasn't been found yet or the target is different from the current target
if (currentPath == null || Vector2.DistanceSquared(target, currentTarget) > 1.0f || findPathTimer < -1.0f)
if (currentPath == null || isDifferentTarget || findPathTimer < -1.0f)
{
IsPathDirty = true;
@@ -162,7 +163,11 @@ namespace Barotrauma
}
}
currentPath = pathFinder.FindPath(pos, target, "(Character: " + character.Name + ")");
var newPath = pathFinder.FindPath(pos, target, "(Character: " + character.Name + ")");
if (currentPath == null || isDifferentTarget || newPath.Cost < currentPath.Cost)
{
currentPath = newPath;
}
findPathTimer = Rand.Range(1.0f, 1.2f);