Skip to content

Instantly share code, notes, and snippets.

@DataGreed
Last active August 21, 2023 17:59
Show Gist options
  • Select an option

  • Save DataGreed/df0c008be1f9269d5160af413e939843 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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
Copy Markdown

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

@behdadsoft
Copy link
Copy Markdown

Thanks.

@Demetree9
Copy link
Copy Markdown

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