Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Link NavMeshes at Runtime

Discussion in 'Navigation' started by handsomejane93, Dec 6, 2018.

  1. handsomejane93

    handsomejane93

    Joined:
    Dec 6, 2018
    Posts:
    4
    Hey everyone,
    We're making a game with automatically generated levels and our types of enemies should be able to traverse all floors and walls in this game. Because of the generation of the surroundings, I am not able to link the NavMesh surfaces manually for our AI to traverse all of the surfaces.



    My question is, would it be possible to connect all surfaces through a script at runtime? I tried autogenerating the OffMesh Links, but I only managed to connect surfaces that would have to be jumped across, or somehow dropped down to, which is not really what I am trying to do here.

    Any kind of help would really be appreciated! :)
     
  2. mdotstrange

    mdotstrange

    Joined:
    Sep 23, 2013
    Posts:
    198
    It is possible with the newer Navmesh system that uses surfaces- I had to do exactly this for a procedural game I made- Here's a link to an older version of the code I used- This small enum class is used by the other script

    What I did was add NavMeshLink's at runtime- the start and end points were set by grabbing a surface's (GetClosestEdge) and/or getting the colliders closest point- It's been a long time so I can't remember the details but its in the code-
     
    handsomejane93 likes this.