Search Unity

Looking for certain Navigation Areas between actual position and destination

Discussion in 'Navigation' started by viperlot, Feb 2, 2018.

  1. viperlot

    viperlot

    Joined:
    Jul 17, 2013
    Posts:
    7
    Hello,

    I have a question about NavMeshes and the Navigation System.

    Is there some way to get the Areas between the Start Position(or any position in the NavMesh) and the Destination Position?

    The point is, i need that the player waits on certains areas, execute some functions and after that resume the way towards the destination.

    I would appreciate any help and advices :)

    Thx
    Tiago
     
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708


    So i havnt done this so im unsure if itll work, but you should be able to do a navagation check finding all points (starts about 25 minutes into this video). At each point do a navagation layer check..
     
  3. viperlot

    viperlot

    Joined:
    Jul 17, 2013
    Posts:
    7
    Thx JBR, this is actually what i need and it helps a lot :)

    For thoose that dont want to watch the Video:

    Code (CSharp):
    1.  
    2. Vector3[] points = navMeshAgent.path.corners;
    3. NavMeshHit navmeshHit;
    4.  
    5. for(int i = 0; i < points.Length; i++){
    6.          
    7. navMeshAgent.SamplePathPosition (NavMesh.AllAreas, 1f, out navmeshHit);
    8. Debug.Log (navmeshHit.mask); //This gives you a Bitset for the Area
    9.  
    10. }
    11.  

    But now i have a new Problem and i hope that someone can give me a advice.

    My new Problem is that my Cornerpoints are to close at the Area Edge and i would like to increase that distance like this:


    Some idea hot to do this?

    PS:
    I allready try to increase Agent Radius int the Render options and on the NavMeshAgent options. No Change...


    Thx a lot!
     
    Last edited: Feb 4, 2018
  4. viperlot

    viperlot

    Joined:
    Jul 17, 2013
    Posts:
    7
    Ok i found a solution but im pretty sure thats not the best way, so if someone still have an advice i would appreciate :)

    The way i use, is to use two cube gameobjects with a navmesh obstacle component and checked the carve option.

    it would look like this:


    Now i have the ideal distance and the Areas can be recognized correctly to execute the functions i need.
     
  5. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    How about finding all path corners and then finding the middle point in between them. Im assuming your corners are ending on areas where several layers meet up. This should put each check directly in a seperated layer.