Search Unity

Question How make pathfinding with several agents work?

Discussion in 'Navigation' started by NewMagic-Studio, Jun 21, 2020.

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    Have been working with Unity pathfinding but dont find a way it works with several enemies.
    If i set them just using local avoidance they push each other making them slide ,which looks horrible
    If i set them as obstacle carve and disable agent cant calculate the pathfinding distance to the player cause agent is disabled so i cant know if agents are near to attack or not. Games really use Unity system?
    Tried other solutions like aaron pathfinding but dont work either, once they reach the target the start to jitter the rotation. Now i am considering behaviour trees package as have a movement package which maybe works the local avoidance without pushing, and also Polarith ai for local avoidance but dont know if it will work. Any advice how to make it work this?
     
  2. TriangularCube

    TriangularCube

    Joined:
    Apr 6, 2016
    Posts:
    16
    Unity's pathfinding system is, like most of it's built-in systems, useful for a place to start, but woefully inadequate for anything more advanced. But that doesn't mean we need to throw it out altogether.

    You know, there are several things you can do to still calculate a navigation path, the most obvious being
    Code (CSharp):
    1. agent.enabled = true;
    2. if (agent.CalculatePath(somePoint, path)) {
    3.     // Do stuff
    4. }
    5. agent.enabled = false;
    or simply ditch Agents and go straight to
    Code (CSharp):
    1. NavMesh.CalculatePath(somePosition, targetPosition, filter, path)
    Now that you have a path, simply write your own movement system and don't rely on Agents.

    With A* Pathfinding Project you can go even further and optimize by utilizing asynchronous path calculations provided by Aron's excellent asset.

    Point is, don't rely on Agents to provide you particularly good entity locomotion, they tend to fairly specific to individual games and not easy to generalize.
     
  3. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    I already tried that, but doesnt work. Obstacles in enemies are carved so after enabling agent finds no path as needs another frame to remove the carve. Tried using NavMesh.CalculatePath( but gives me invalid path and zero corners, tried using NavMesh.SamplePosition( to give the nearest point to the enemies positions as use obstacle carve but still gives me invalid path, i tried it at Start method but gives me invalid path and zero corners, but actually using agent.destination finds a path, tried using remainingdistance but enemies jitter when reach the position, maybe cause its the limit of the path given by sampleposition, tried to increase stoppingdistance but doesnt solve it dont know why. So millions of problems that make it doesnt work
    If i just discard agents then i have no local avoidance, if enemies find each other in the path, i cannot use avoidancepriority and they will stuck if go one against another as happens when several try to go into a narrow space like a door
    Sample position and calculate path give true but then path is invalid with zero corners
    Also there is another problem, dont know why even though enemies are set as obstacles sometimes they move to player going too near, but they should stay stuck
     
  4. Extured

    Extured

    Joined:
    Feb 25, 2020
    Posts:
    1
    thanku
     
  5. jadvrodrigues

    jadvrodrigues

    Joined:
    Feb 25, 2020
    Posts:
    12
    You might be interested in this https://forum.unity.com/threads/cus...ts-avoid-the-other-non-moving-agents.1005998/.