From d3437c4428e64678c1ce5feba00fe8c78a5330f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DESKTOP-KKNPJ97=5CJos=C3=A9?= Date: Wed, 5 Jan 2022 22:10:43 +0000 Subject: [PATCH] The HiddenAgent's position is now updated in the CustomNavMeshAgent's Move and Warp methods so the agent's path can get recalculated sooner. --- Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs b/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs index f2d5202..c0ac212 100644 --- a/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs +++ b/Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs @@ -358,6 +358,10 @@ NavMeshAgent NavMeshAgent public void Move(Vector3 offset) { if (NavMeshAgent.enabled) NavMeshAgent.Move(offset); + + // update hidden position now (instead of waiting for the next frame) + // so the agent's path can get recalculated sooner + if (HiddenAgent) HiddenAgent.transform.position = transform.position + CustomNavMesh.HiddenTranslation; } /// @@ -370,13 +374,19 @@ public void ResetPath() } /// - /// Warps agent to the provided position. + /// Warps agent to the provided position. If the agent has a path it will not be reset. /// /// New position to warp the agent to. /// True if agent is successfully warped, otherwise false. public bool Warp(Vector3 newPosition) { - return NavMeshAgent.Warp(newPosition); + bool result = NavMeshAgent.Warp(newPosition); + + // update hidden position now (instead of waiting for the next frame) + // so the agent's path can get recalculated sooner + if (HiddenAgent) HiddenAgent.transform.position = transform.position + CustomNavMesh.HiddenTranslation; + + return result; } ///