increase node search radius for escaping

This commit is contained in:
in0finite 2022-04-17 22:24:03 +02:00
parent 8318a3c9b1
commit e823af2e22
2 changed files with 6 additions and 6 deletions

View file

@ -7,6 +7,8 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
private readonly PathMovementData _pathMovementData = new PathMovementData();
public PathMovementData PathMovementData => _pathMovementData;
public float nodeSearchRadius = 500f;
public override void OnBecameInactive()
{
@ -31,7 +33,7 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
if (!_pathMovementData.destinationNode.HasValue)
{
PedAI.FindClosestWalkableNode(_pathMovementData, _ped.transform.position);
PedAI.FindClosestWalkableNode(_pathMovementData, _ped.transform.position, this.nodeSearchRadius);
return;
}

View file

@ -134,14 +134,14 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
return targetNode.Position + offset.ToVector3XZ();
}
public static void FindClosestWalkableNode(PathMovementData pathMovementData, Vector3 position)
public static void FindClosestWalkableNode(PathMovementData pathMovementData, Vector3 position, float radius = 200f)
{
if (Time.timeAsDouble - pathMovementData.timeWhenAttemptedToFindClosestNode < 2f) // don't attempt to find it every frame
return;
pathMovementData.timeWhenAttemptedToFindClosestNode = Time.timeAsDouble;
var closestPathNodeToWalk = PedAI.GetClosestPathNodeToWalk(position);
var closestPathNodeToWalk = PedAI.GetClosestPathNodeToWalk(position, radius);
if (null == closestPathNodeToWalk)
return;
@ -225,10 +225,8 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
return previousNode;
}
public static PathNode? GetClosestPathNodeToWalk(Vector3 pos)
public static PathNode? GetClosestPathNodeToWalk(Vector3 pos, float radius)
{
float radius = 200f;
var pathNodeInfo = NodeReader.GetAreasInRadius(pos, radius)
.SelectMany(area => area.PedNodes)
.Where(node => !node.Flags.EmergencyOnly)