Search Unity

Calculate all possible paths?

Discussion in 'Navigation' started by nbg_yalta, Aug 12, 2015.

  1. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    Hello! So this is a question... Is there a way to calculate for agents all possible paths to the player? I want to make something like this:

     
    neno1204 likes this.
  2. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    BUMP!

    Can someone tell me Is it possible, and if not, which pathfinding solution should I use?
     
  3. TEBZ_22

    TEBZ_22

    Joined:
    Jan 28, 2014
    Posts:
    37
    As long as you keep it simple, and the game engine have some knowledge about the world it might be possible.
    I have not tested this, but...
    If there are only a limited number of doors into a room/house , then block them all except one with NavMesh Obstacles and calculate each path.

    If the world are more complex, then computing time it might be a problem:
    A general solution might be to ( using a binary counter and) try all combinations of blocked and unbloced doors, discarding the duplicates.
    I think that one might be able to skip all combinations where a room (or any closed boundary) have more than two doors opend. (Start & finish rooms, only one)

    (perhaps someone smarter than me can find a better way)
     
    Last edited: Aug 15, 2015
  4. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Wow, this is interesting. I can see a few ways of doing this, but what you should do would be more project specific than this. This is the best general way to do this, I think:

    Could be done easily with something like the A* Project, because it contains a feature where you can make a path which must include a certain point, but it is still very possible in the unity builtin navmesh system, I think.
    If you can get all the doors connected to a room, you could make a path from the avg./mid position of your red guys (so you don't need to calculate a path for each red guy induvidualy), to each door. Now you have a number of paths equal to the amount of doors in the room. Now calculate a path from each of the doors to the desired/green point.

    Now that you have your paths, you should have a blackboard, a script equally accessible by all agents of a specific group, which controls the tactics of your red guys. This blackboard would distribute the red guys equally by each door/decide which red guys should cover what door, and then tell them to do that. Again, saving time and code etc. by doing it once.

    Shameless advertisment (Im sorry): You would need to store the paths after calculating them. You know what would make that really really easy? Simple Option Stacker! Find the asset store and online API link in my signature!

    How smart is the AI, btw? Is it like a tactical top-down shooter thing, where the AI acts realistically? Or do they know what ways the enemy are looking? Because if so you could cheat. Make some sort of influence map or angle/raycast/fustrum AABB planes check to see if an enemy can see a door, and then make extra decisions based on that. Just a random add-on!

    Also you might want your blackboard script to constanty calculate a path to the closest rooms in the background, so you will get a constant framerate instead of framedropping on complex levels!