Search Unity

How can I tell how many OffMeshLinks are between Agent and Destination?

Discussion in 'Navigation' started by McGunn, Oct 16, 2015.

  1. McGunn

    McGunn

    Joined:
    Aug 7, 2012
    Posts:
    33
    Hi,
    I'm working on a game prototype in which the main character is a nav mesh agent. There are many "Jump Points" (OffMeshLinks) on my nav mesh where the character jumps from point to point, however:

    -I need to be able to see how many OffMeshLinks are between the Agent and the Destination, so that I can cancel the movement if there is more than one. The point of the game is to identify the next jump-point instead of just being able to click the final destination and watch the character navigate the whole level. I know this must be possible, but I cannot figure out how.
     
  2. McGunn

    McGunn

    Joined:
    Aug 7, 2012
    Posts:
    33
    My only possible idea is VERY extremely hacky:
    - Have a second invisible agent just used for gathering info.
    - When the character is given a destination it uses the invisible agent for info like this:


    Code (CSharp):
    1. if (navMeshAgent.nextOffMeshLinkData != null)
    2. {
    3.  
    4. invisibleAgent.transform.position = navMeshAgent.nextOffMeshLinkData.endPos;
    5. invisibleAgent.destination = navMeshAgent.destination;
    6. if (invisibleAgent.nextOffMeshLinkData != null)
    7. {
    8. navMeshAgent.destination = transform.position
    9. //Maybe something here to tell the player that it's an invalid target position
    10. }
    But I'm sure I will run in to problems as the path for the invisible agent probably doesn't get created instantly to grab that information, so I'd have to put it into some sort of enumerator.

    Still, this hacky method is very poor and I would really really appreciate any insight into the matter!
     
  3. bxzr

    bxzr

    Joined:
    May 13, 2019
    Posts:
    5
    Recently I have an issue to get offmeshlinks from baked navmesh, but I can not fin any way. If you have got some method, please teach me, thanks a lot!