Skip to content

Instantly share code, notes, and snippets.

@DataGreed
Last active August 21, 2023 17:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DataGreed/df0c008be1f9269d5160af413e939843 to your computer and use it in GitHub Desktop.
Save DataGreed/df0c008be1f9269d5160af413e939843 to your computer and use it in GitHub Desktop.
Checks that NavMeshAgent reached destination or gave up trying
public bool ReachedDestinationOrGaveUp()
{
if (!_navMeshAgent.pathPending)
{
if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance)
{
if (!_navMeshAgent.hasPath || _navMeshAgent.velocity.sqrMagnitude == 0f)
{
return true;
}
}
}
return false;
}
@tqtran7
Copy link

tqtran7 commented Jun 9, 2022

public static bool ReachedDestinationOrGaveUp(this NavMeshAgent navMeshAgent) { if (!navMeshAgent.pathPending) { if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance) { if (!navMeshAgent.hasPath || navMeshAgent.velocity.sqrMagnitude == 0f) { return true; } } } return false; }

Will allow you to extend this method directly to the navMeshAgent.

@CarlZeidler
Copy link

Thanks, haven't done extensive testing yet but works well so far!

@behdadsoft
Copy link

Thanks.

@Demetree9
Copy link

You guys are awesome! Thanks for the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment