Search Unity

NavmeshAgent alternative paths?

Discussion in 'Navigation' started by drsalvation, Mar 26, 2022.

  1. drsalvation

    drsalvation

    Joined:
    May 2, 2014
    Posts:
    48
    I'm not sure if this has been asked before, I'm trying to understand a bit more how navigation agents work.
    I'm trying to make the AI in my game not be as predictable as using a default agent, and the closest example I can think of is the following scenario:

    The player is at the bottom, the white smiley face. There's a yellow obstacle, a desk or something and the player is right behind it. The staircase only comes down from the left side, and there are 2 zombies walking down from it trying to get to the player. The orange path is by the shortest route, the one unity will automatically use when you use SetDestination. Both zombies will follow the exact same route.

    upload_2022-3-26_14-8-57.png


    I'm wondering if there are ways to make AI pick the dotted blue route -which isn't the closest path possible, but it's still an alternative, which will also help to ambush the player- using navigation agent components?

    One of the solutions I could think of right off the bat is setting a trigger which enables a navmesh obstacle when the first zombie passes through, but that feels hardcoded as heck, since this means every level would NEED a gate like that that, instead if it can be chosen via code, then the AI can be a bit more dynamic. So if possible, I'd rather avoid obstacles as much as possible and keep the path choices on the AI.

    One of the things that helps occasionally is that zombies have random chances to strafe around the player, so this can alter their path too, but it won't guarantee it (to be fair, I'm not expecting a random choice of shortest path or alternative path to also guarantee that each zombie will take a different path, they might take the same after all).

    I'm also not looking for people to write the code for me hehe, I'm just wondering if there's any approaches or any components I'm not aware of which can aid this bit? upload_2022-3-26_14-8-57.png
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300