Search Unity

easiest way to make an agent to visit all the navmesh area ?

Discussion in 'Navigation' started by Thibault-Potier, Sep 27, 2018.

  1. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Hi guys

    Imagine that you are in your garden, you close your eyes and throw randomly your keys.

    You will have to "scan" carefully the whole area to find them.

    That is pretty much the behaviour i want to simulate. I'm planning to use the navmesh and navmeshAgent tools.

    * Before starting to code, is there a built-in solution to achieve that kind of task for navmesh agent ?

    * if not, i suppose i will have to "fill" my navmesh with waypoints that the agent would have to visit to perform a full "scan" of my area. So the problem is evolving:
    - let's say that i drop waypoints regularly all over my area. How to find the best sequence of waypoints to optimize the path ? The solution seems easy for a squared area, but what about more complex shapes ?

    * Once this will be achieved, i would like to share this task with multiple agents (if you are not alone looking for your keys, how to optimize the research between you and your friends)

    So if you have ideas or solution, that would help :)
    Thanks !
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Sounds to me like you should make a behaviour that plots a "patrol path" over your navmesh and keeps doing that until it's found the object you want.
    Simplest approach I can think up is to start your agent off in a corner of the navmesh and have it travel down the side by setting its goal to the next corner. When that's done you move the agent a little sideways and then set its goal back to the other side.
    Keep doing this until they find their object, which you can probably detect by putting a trigger on it.
    This will not be guaranteed to cause your agent to look everywhere, especially with a complex level layout, but this should set you up to expand on the idea.
    Perhaps you could divide up your area into cells and have your agent keep track what cells he's visited and what cells he hasn't, setting the closest unvisited cells as their next target.