Search Unity

Moving NavMeshAgent on random path

Discussion in 'Navigation' started by Lekret, May 6, 2021.

  1. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    358
    Hi, do anyone know the way to move randomly on NavMesh?
    Let's say I have a map with two bases and three lanes connecting them, and I said to my NavMeshAgent that it need to move from one base to another. Agent will move on middle lane since it's the shortest, but is there a way to randomize it so my Agent will move on any lane/path he can find, without checking was it the most short or not?
     
  2. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    The NavMesh will always try to find the shortest distance to a path. If you want to force the enemy to go down a particular lane, you can choose which lane, then choose the midpoint of the path to the other base as the first destination, once the agent gets there, set them to go to the other base