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

Improving Path Variety/Randomness

Discussion in 'Navigation' started by Morgenstern_1, Dec 19, 2016.

  1. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    Hi guys,

    I'm looking for a little advice as I'm quite new to building believable AI. I've got a bunch of bots up and running using NavMeshAgent and they're working well, BUT because their is always a "best" path from one location to another I find that if they wind up going to the same place at the same time they all wind up following each other in a little conga line. This really makes them stand out as being not human players.

    There are no teams in the game I'm building, each bot is acting as an individual, so I don't need them to behave as though they were a squad. All I want is for 2+ bots walking down a corridor to spread out a little.

    Any advice on how to tackle this problem would be appreciated.
     
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Local object avoidance can sometimes help a bit with this. As can adding different cost areas. You can also, if you know before hand the navMesh "look" (which you will since it is baked) do some manual offsetting from the waypoint/corner positions. This can be manual, like, if Bot is going to position X, add Y vector to that position, so it has a bit of an offset. You could also add in "waypoints" which define the offsets, rather then using something random like position in unit circle or whatever.
     
  3. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    Thanks for the ideas!

    I quite like the idea of just offsetting the points on their path a little, perhaps pushing them away from the nearest wall by a small, random amount would help. The end targets do differ so I'm not as worried about them as the points on their paths in between.
     
  4. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
  5. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    you can use that offset-corner as a new destination for the navMesh itself to resolve to - i don't actually allow the NavMeshAgent to control (move) my cars - all the movement is done "manually" - i use the navMeshAgent to figure out where i should be going, and use its desiredVelocity as how i'd like to move. So if you are using NMA for all your movement, then other then setting the offset-corner as your next destination, i'm not sure how you'd do it....

    Oh, ok, here is a very hacky possible solution. Add a bunch of NavMeshObstacles to the locations/lanes, don't let them carve the mesh though, and randomly-ish turn them on and off - the NavMeshAgent will use Local Obstacle Avoidance to try to get around them, but if they turn on/off randomly, each agent will be avoiding them for a different period of time, making each of their movements different. ;)
     
    Morgenstern_1 likes this.
  6. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    Ah that is a pain! Sometimes the bots wind up moving quite close together so sadly the obstacle route wouldn't work - they'd wind up ALL avoiding an invisible object which would look even weirder. Plus I'll be honest and say I find that the local object avoidance in Unity is poor at best.

    Sounds like I might also need to make my own implementation of NavMeshAgent, which is a pretty huge job in itself. Such a shame they don't let you supply your own, edited, path. Any tips/things to avoid for creating custom agents (given that you've done it once already haha)?
     
  7. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Without totally understanding your setup, or even how you want them to look, even if you keep the NavMeshAgent stuff, you can do some things to vary your movement. Randomly inc/dec your top-speed a bit, so all the agents move at slightly different rates - this could be an on-going variance, or just an offset which gets set at "start". LOA is maybe not great but can help, even when doing the conga line, especially with different speed objects, to force a bit of movement into the bots. You can also briefly turn off the NMA's updating, and do your own for a frame or two, just slightly wandering/changing rotation, to add a bit of variance. These are maybe not totally enough to make them look great, but they are pretty simple and might be "enough". Again, if your movement code is divorced from the NMA, it makes it way easier to do this kind of variance stuff. Also, don't subclass NMA, just put it on the GameObject with your own "Mover" script, and reference it to get all the info. Also setting up different cost areas in the NavMesh, so your agents don't hug the walls or whatever but take "roads" can help a lot too.
     
  8. Morgenstern_1

    Morgenstern_1

    Joined:
    Jul 1, 2013
    Posts:
    34
    I'm basically attempting to mimic humans moving around an environment: think of the project like a slow-paced, strategic FPS. The bots do sometimes increase their speed to a run at the moment, but there are rules in place to govern when they can/should do this. For the sake of making it fair to real players playing against them everyone needs to be locked to the same walk/run speeds.

    A custom mover script, switching back to the NavMeshAgent when there are obstacles nearby, sounds like it might be the best way to go. I'm also going to tinker around with cost areas on the NavMesh to see if I can see an improvement without too much hassle.

    Thanks so much for all your help. Sounds like I've got a bunch of stuff to look into/try out!