Search Unity

Navmesh's path with other agents obscuring it

Discussion in 'Navigation' started by Nihil688, Apr 3, 2020.

  1. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    I have about 100-200 agents that are moving towards a single place. Every few seconds Im checking whether they can go to that place. My problem is that currently even though there are other agents that have reached the place and are obscuring the path for others, PathCalculation returns that path is found and is complete. Is there a way for me to get that actually the path is incomplete since others are infront of it?

    ( I have tried priority avoidance depending on distance but nothing changed )
     
  2. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
    Nihil688 likes this.
  3. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    I understand a lot more after reading through these and RTS group pathfinding although in my case I'm not sure I need group pathfinding rather I need group positioning when they reach the target. Possibly the same solution to this problem but my agents are individually going after the same target rather than a group. They end up in a group when they reach their target but they are limited by the space available and their size.

    I thought of creating slots around the target and positioning them there but that might start to look organized instead of rough which I prefer
     
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
    Here is diagram from https://docs.unity3d.com/Manual/nav-InnerWorkings.html
    upload_2020-4-3_20-16-9.png
    As I understand, NavMesh know nothing about obstacle avoidance, as all is done through Agent.
    Agent knows about other Agents and Obstacles, but not about physics.

    Essentially agent cast Circle radius of NavMeshAgent.radius against Agents and Obstacles and use NavMeshAgent.Raycast to avoid it.

    Bad news, its that you are not allowed to use NavMeshAgent.Contact. And NavMeshAgent.Raycast does not hit Agents or Obstacles.

    So, you need to implement avoidance though physics Physics.GetContact and NavMeshAgent.Raycast. On every contact - raycast where you can go, and update agent with NavMeshAgent.nextPosition. And you will get the same what Agent do now)

    Now add something like this https://unitycoder.com/blog/2019/05/06/ray-marching/ - to get over group on agents)

    Maybe its better to implement agent from scratch. Any way, you need to raycast your path trough.
     
    Nihil688 likes this.
  5. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    @vhman sure I understand all that although even if I went through the trouble of extending the system I have so many agents that it would need possibly something more than just checking what's in front with raycasting.

    In the meantime I created an organisation path system so that the end points are organized rather than all of the agents going to the same end point. As such they should more rarely collide and they d never care about other agents since they all have different points to go to.

    Looking into it in more detail though it still has issues which has nothing to do with collision or agents being next to each other atm. The red ray shows where the agents want to go but they never reach it. The two closer to the center reached ok but the rest don't reach and just run on spot forever. Their radius is much smaller than the space they have to move so that shouldn't be a problem. They even pass through the destination, stop after a while and again stay there forever, not going back. Their Angular Speed is 360 so they should rotate too but they don't.

    Capture.PNG