Changing Navmesh Agent Destination while on OffMeshLink

Viewed 20

My player uses a NavMesh agent that moves the player towards the location where the mouse is clicked. The game world is composed of separate NavMeshes connected by OffMeshLinks.

Assume the following setup:

  • NavMesh A and NavMesh B connected by a bidirectional OffMeshLink.
  • The player's NavMesh agent (with auto-traversal of NavMeshLinks) is on NavMesh A.
  • I click on NavMesh B.

Now the agent will move to NavMesh B through the OffMeshLink. Say that during the movement on the OffMeshLink I decide that I don't want the agent to move to NavMesh B e.g. I see an enemy object on NavMesh B; and consequently I click on NavMesh A to go back to a safer place.

What happens is that the agent will continue traversing the OffMeshLink (towards NavMesh B), not taking into consideration the new destination (NavMesh A).

How would I fix this? How would I make the agent listen to the updated destination while on the OffMeshLink?

1 Answers

I don't think you can stop an agent from traversing an Off mesh link but you can try and update the Offmesh link End point at runtime to move the player to different position. Remember to check "auto update position" on Off mesh link component.

I am not sure this will work but you can give it a try.

Related