Search Unity

Navmesh Enemy AI, Encircle Target

Discussion in 'Navigation' started by msurz89, May 21, 2022.

  1. msurz89

    msurz89

    Joined:
    Apr 13, 2021
    Posts:
    8
  2. adventurefan

    adventurefan

    Joined:
    Jan 17, 2014
    Posts:
    230
    You just have write a lot of your own behavior code for AI on navmesh. Sadly that's just how the nav AI system is. It's not fleshed out and able to do anything much in the way of behaviors. No fleeing/flocking/hiding/specific rules for certain obstacles... etc... it's just a very basic start of a nav system.
     
    msurz89 and DwinTeimlon like this.
  3. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    Yeah, but you can cheese and cheat the hell out of it. We're building video games, not rocketships! ;)

    I added a gameobject to my enemy that scoots over to the player's world position, and then starts orbiting it on the X / Z axis. So basically the player is surrounded by a cloud of objects that are completely invisible. These objects do a RayCast downward and if they hit a NavMeshSurface, they update a Vector3 position in the enemy component.

    I simply have the enemies walk to this custom position. I could randomize their path a little further by varying the radius, speed and direction of the orbiter object, but it already feels more like a rushing horde then when I would simply feed them the player position. Remember: cheating is not only allowed, it is fully encouraged.