Search Unity

2D NavMesh PathFinding......

Discussion in '2D' started by Vinnie711, Nov 8, 2017.

Thread Status:
Not open for further replies.
  1. chunky_octopus

    chunky_octopus

    Joined:
    Apr 11, 2015
    Posts:
    14
    Hi @vhman, yes it is a tile map. As mentioned, I already tried to tweak the agent radius and the voxels but there is still a problem in some concave areas, like these two below circled in red.
    It is weird because you can see how the concave section in gree seems to be baked correctly.

    upload_2022-3-7_12-56-4.png
    Finally, this is my setup.

    Screenshot 2022-03-07 at 12.56.22.png
     
  2. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    @chunky_octopus

    Looks kind of crazy. Try set default area "non-walkable" and add "navmeshmodifier" to tilemap with "override area" - "walkable".

    If you have isolated project with this issue send me PM, I will take a look.
     
  3. chunky_octopus

    chunky_octopus

    Joined:
    Apr 11, 2015
    Posts:
    14
    Ah! Stupid error on my side, I inadvertently used a brush to "delete" some tiles so I added "walls" that just look like the ground.
    Screenshot 2022-03-07 at 15.17.16.png
    The Nav surface was doing its job but I just couldn't see the walls.
    Now it's fixed, thanks for the tip to invert the navmap and look at the non-walkables.
    Screenshot 2022-03-07 at 15.21.30.png
     
    vhman likes this.
  4. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    70
    HI, does this work with just 2d sprites or does it need a tilemap?

    I would like to make a sprite based game and use either 2d or 3d colliders to generate the nav mesh. Is this possible, if so, what is the best approach?

    Thanks,

    Adam
     
  5. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
  6. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    70

    Ah amazing, thanks!

    Another question that may not be directly related an more of a NavMesh thing, but do you know how to make the mesh tighter? At the moment, there is quite a lot of space around my sprites, I would ideally like the mesh to reach the edges of the sprites.

    Thanks.
     
  7. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    bz_apps likes this.
  8. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    @vhman I'm not sure if I mentioned this to you or not but I believe you'll be using this in your code; Collider2D.GetShapeHash previously went away and calculated a unique hash for the Collider2D which involved iterating all its geometry. This is fast but for really complex Collider2D with lots of physics shapes, it became non-trivial so things like TilemapCollider2D or the new CustomCollider2D.

    I wanted to mention (possibly again) that this hashing is now done incrementally as the Collider2D are created or changed which makes it super fast now. If you now call the above, it'll just return you the hash instantly so it's really quick to use.
     
    vhman likes this.
  10. ChiuanWei

    ChiuanWei

    Joined:
    Jan 29, 2012
    Posts:
    131
    @bz_apps hello , if i have the bake scene to generate the "NavMesh-NavMesh" data. and can i use this asset to other runtime scene ??
     
  11. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    @ChiuanWei I believe so, but never tried.

    Need some time to investigate.
     
  12. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    bz_apps and ChiuanWei like this.
  13. ChiuanWei

    ChiuanWei

    Joined:
    Jan 29, 2012
    Posts:
    131
    because the BIG world was created and generate the navmesh. but runtime the world is loaded with many separates. i and by the way . if two scenes were loaded, can i switch the camera and swtich the active navmesh ?
     
  14. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    ChiuanWei likes this.
  15. ChiuanWei

    ChiuanWei

    Joined:
    Jan 29, 2012
    Posts:
    131
  16. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
  17. ronald_ES

    ronald_ES

    Joined:
    Sep 21, 2021
    Posts:
    5
    Is it possible to get it to work with tilesets & colliders at the same time?

    In the attached picture I have a Startship object that uses a physics collider but I also have a grid with ground and wall tilesets. I already tried different combinations like adding the grid as a child to the navmesh object but it didnt work.

    Thanks
     

    Attached Files:

  18. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hello @ronald_ES

    Yes, its possible. Just add tilemap 2d collider to tilemap, and move it as a child for navmesh.

    n this weekend I'm planning to finish extensions system that will have more flexibility.
     
  19. ronald_ES

    ronald_ES

    Joined:
    Sep 21, 2021
    Posts:
    5
    Great it works thank you
     
  20. ronald_ES

    ronald_ES

    Joined:
    Sep 21, 2021
    Posts:
    5
    Is there a way to know if the builder is currently building when using the NavMeshSurface2d.BuildNavMeshAsync() operation? The unity docs says theres an isRunning static bool in the NavMeshBuilder class but doesn't exist when I try to use it.
     
  21. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Not quite sure why you need it. AsyncOperation has 'isDone' and 'progress' fields.

    But in docs there is a note Note: There are two classes with the name NavMeshBuilder. They are declared in two different namespaces: UnityEngine.AI and UnityEditor.AI.
     
  22. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Hello All,

    My weekly update is here. So I refactored code a bit, added extensions provider abstraction layer and introduced extension where we can specify root sources of navmesh. I will try to add caching extensions for efficient navmesh runtime update and will merge to master.. or I will get lazy and just pull everything as is)
    https://github.com/h8man/NavMeshPlus/tree/navmesh-extensions

    Regards,
     
  23. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    Weekly update! Extensions system are in master. No cache implementation right now. System pretty fresh and fragile, new updates are comming.
     
  24. sinketita

    sinketita

    Joined:
    Jun 30, 2018
    Posts:
    13
    Hi! Is there any way to make somehow layered navmesh? I have a map that has several layers and generated navmesh looks not very fitting due to obstacles placed on different layers. I simply wonder how someone would make that.
    upload_2022-4-17_15-58-2.png
     
  25. sinketita

    sinketita

    Joined:
    Jun 30, 2018
    Posts:
    13
    Hmm, it seems I got this, maybe I should use layer option in NavMeshSurface and then change navmeshes according to layer. But maybe there is more effective way?
     
    kirillkrasnoruckij likes this.
  26. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    @sinketita ,

    Layers and NavMeshSurface layers is the way to go. But than you should connect navmesh layers together and handle navmesh links.

    I don't have a sample for this case, nor wiki page or guidelines. :(

    take a look at https://github.com/Unity-Technologies/NavMeshComponents it has more samples. (navmesh plus if a fork)
     
  27. ronald_ES

    ronald_ES

    Joined:
    Sep 21, 2021
    Posts:
    5
    Is the sampling method compatible? I tried using it here. First it detects the Tilemap2d collider which it does properly, then I pass the collider position and the area mask to the method. Can't get it to go to line 68 where it detects unwalkable areas.

     
  28. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
    @ronald_ES, Yes. it just extension of NavMesh system.

    But I have some idea - you can not sample point on unwalkable area (as it not part of navmesh). So check in opposite and reverse if condition:

    Code (CSharp):
    1. mask = -1 ~ (1 << areaIndex);
     
  29. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    356
Thread Status:
Not open for further replies.