Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question NavMeshAgent stops moving when it can't find a path to destination

Discussion in 'Navigation' started by tigger, Jul 4, 2023.

  1. tigger

    tigger

    Joined:
    Jan 8, 2013
    Posts:
    95
    My scenario is that I have a moving target object that a NavMeshAgent-controlled object (the "follower") pursues, but I don't want the follower to follow the target object into certain areas that are "off limits."

    This generally works fine. However, the follower stops moving the instant the target enters the "off limits" area (because at that point, there simply is no path to the destination). I'd like the follower to keep moving until it reaches the boundary of the off-limits area. As it is, it will simply stop, and that stopping point is sometimes rather far away from the boundary and the target.

    Is this possible through configuration of the agent or through scripting?

    Thank you.
     
  2. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    47
    Do a check if the navAgent has a valid path. Link

    If it returns false then set its destination to be in the direction of the enemy * current transform.forward