Search Unity

Move Navmesh agent onto Navmeshsurface from outside the surface

Discussion in 'Navigation' started by mrCharli3, Jan 8, 2020.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Is there any way I can accomplish this seemingly easy task that actually seems to be quite difficult?

    I have a bunch of units on a boat, I move the boat until it hits land (Navmeshsurface), then they disembark. However, since the boat is not a Navmeshsurface, I cannot tell the agent to move.

    Is there some way this can be solved that Im not thinking of? I cannot findany material on it and have not had any accuess myself.
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    As agents can only be moved on a NavMesh, you could do the following.
    Add a
    NavMeshModifier
    or
    NavMeshModifierVolume
    to your boat and set to "unwalkable". As soon as your boat reaches the shore, set the
    NavMeshModifier
    to "walkable" and update your NavMesh.
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    You mean that will merge to boat navmesh into the "main" navmesh? I guess if they are on the same layer that might work. Since if the game thinks they are 2 different navmeshsurfaces, I would need a navmeshlink I think.

    I dont even have to set it to unwalkable, I can just wait to activate the units agents until the boat reaches the shore :)

    I was thinking to that some kind of magic with navmesh link might work too, but havent had time to try it yet, and not sure if I can modify it at runtime. Your way seems easier.
     
  4. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Yes, in a best case scenario it would only be one NavMesh.
    If the boat and the terrain are on different height you might need a NavMeshLink. It's very much depending on your NavMeshSurface bake settings.
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    For anyone coming here for an answer.

    I ended up adding a navmeshlink as children of my boat, then I activate them when the boat hits ground, this worked surprisingly well.

    I use 2 navmeshsurfaces, one for my ground, and one for my boats, mainly so I do not have to generate the entire navmesh every time a boat lands, then I just use surface.BuildNavmesh() when the boats hit land, and send my units to theri destination :)
     
    DwinTeimlon likes this.
  6. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    I would recommend to rebuild your navmeshes in game asynchronously with

    NavMeshBuilder.UpdateNavMeshDataAsync
    . This enables you also to rebake big NavMeshes without any remarkable hiccups.
     
  7. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Thanks, although in me scenario the navmesh has to be baked before the next command is called, so guess that could cause some issues.