From e823af2e2201423ed6754744a173d90e520f88ca Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 17 Apr 2022 22:24:03 +0200 Subject: [PATCH] increase node search radius for escaping --- Assets/Scripts/Behaviours/PedAI/EscapeState.cs | 4 +++- Assets/Scripts/Behaviours/PedAI/PedAI.cs | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Behaviours/PedAI/EscapeState.cs b/Assets/Scripts/Behaviours/PedAI/EscapeState.cs index 691c8241..a1edc7be 100644 --- a/Assets/Scripts/Behaviours/PedAI/EscapeState.cs +++ b/Assets/Scripts/Behaviours/PedAI/EscapeState.cs @@ -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; } diff --git a/Assets/Scripts/Behaviours/PedAI/PedAI.cs b/Assets/Scripts/Behaviours/PedAI/PedAI.cs index aab97ae8..7eda4af1 100644 --- a/Assets/Scripts/Behaviours/PedAI/PedAI.cs +++ b/Assets/Scripts/Behaviours/PedAI/PedAI.cs @@ -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)