Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Use NavMeshAgent for multiple paths

Discussion in 'Navigation' started by BestCar11, Dec 9, 2018.

  1. BestCar11

    BestCar11

    Joined:
    Aug 2, 2018
    Posts:
    3
    I have NavMeshAgents in a simple orthogonal map with two paths of the same length. They spawn at one point. (I am creating a Tower Defense game.) The NavMeshAgents always travel in the same one of the two paths. How do I make half of the agents go the other path?
    If more detail is needed, tell me.
     

    Attached Files:

  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Agents with the same spawn position and destination will always result in the same path with navigation unless they have properties preventing them from doing so (like one path being more narrow than the other).
    A simple way of making the agents alternate between the two paths would be to place a NavMesh Obstacle at the intersection that "gates off" the path they normally go down on, and toggle that Obstacle during gameplay (for example, every X agents that pass the intersection, the Obstacle is toggled).