Skip to content

Commit

Permalink
The HiddenAgent's position is now updated in the CustomNavMeshAgent's…
Browse files Browse the repository at this point in the history
… Move and Warp methods so the agent's path can get recalculated sooner.
  • Loading branch information
jadvrodrigues committed Jan 5, 2022
1 parent fae06f4 commit d3437c4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Assets/CustomNavMesh/Scripts/CustomNavMeshAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand All @@ -370,13 +374,19 @@ public void ResetPath()
}

/// <summary>
/// Warps agent to the provided position.
/// Warps agent to the provided position. If the agent has a path it will not be reset.
/// </summary>
/// <param name="newPosition">New position to warp the agent to.</param>
/// <returns>True if agent is successfully warped, otherwise false.</returns>
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;
}

/// <summary>
Expand Down

0 comments on commit d3437c4

Please sign in to comment.