Search Unity

2D NavMesh PathFinding......

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

  1. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    62
    @MelvMay Could you please provide a small tutorial on how to set up the environment?

    In my case I have a grid with collider, which I put the NavMeshSourceTag2D component on, and then press 'bake' on NavMeshBuilder2D, which is on the parental object relative to the grid collider. But somehow I cannot see the nav mesh appear on the scene.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,051
    Unfortunatley I cannot provide a tutorial and that code hasn't been released officially and isn't supported at all. I'm not actively working on this either, other devs are. I implemented the mesh-creation stuff for 2D colliders only.

    The way hackweek works is that a project is worked on by devs who often don't normally work in that area. In this case, this feature is being worked on by devs who have to allocate time to it specifically post hackweek. Unfortunately that means a delay. AFAIK Sept will be when it's worked on. I was hoping it'd be soon after hackweek but unfortunately that wasn't the case even though I got the native change in very quickly.

    I'll contact the devs and ask if they have any ideas though. I do recall there being some issues about the bounding box and it being rotated but nothing that required a native fix, just something to watch out for. I'll see if I can find out for you.
     
  3. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    62
    Thank you very much, looking forwards to use it when it's ready!
     
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
    Just started new branch for 2019.3 and new feature "Physics Colliders", to use Mesh from colliders (see above).
    And it kind of works. After I will resolve most of the issue, source code will be available in my repository.
    upload_2019-8-21_2-18-54.png
     
    MelvMay likes this.
  5. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
    Hi All.

    Now NavMeshPlus can bake sprites placed inside Grid. https://github.com/h8man/NavMeshPlus

    And here it is: https://github.com/h8man/NavMeshPlus/tree/PhysicsColliders.Unity2019.3
    New branch for 2019.3 and new feature "Physics Colliders"
    It does not work for all composite colliders in test scenes for RedHotSweetPaper, but you can experiment.
    Sometimes collider.CreateMesh(false, false) return null, so watch for the console logs.
    Here is comparison of master and PhysicsColliders.Unity2019.3 branches
    upload_2019-8-22_1-4-6.png
     
    MelvMay likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,051
    It returns null if there are no shapes to create. The only other case is where if it sees edges where the last vertex overlaps the first vertex which on a composite is always the case (when outline mode is on) so that's very odd.

    You can see this on an EdgeCollider2D with EdgeRadius=0. Create a few lines and you'll see no mesh created from it (infinitely thin line). Then change the last edge so that it overlaps the first creating (say) a box. It'll create a mesh from that.

    If you have a reproduction case where it returns NULL indicating a mesh cannot be created where you think it should then it'd be great to see that.

    EDIT: Thank you for adopting this, it's very much appreciated. Ping me if you need anything.
     
    Last edited: Aug 22, 2019
  7. Node

    Node

    Joined:
    Jan 31, 2013
    Posts:
    1
    hi folks. first of all, thanks vhman for the package! i'm building something similar to a 2d strategy game but i'm having a few problems: there are around 5 agents or so controlled at once that should have the least influence on each other as possible, so the radius and height should be as tiny as possible. i tried it with very small values (also baked the navmesh with these values), but if it's smaller than 0.1 the agents sometimes don't move at all. i also have a navmeshlink with a broader width that closes the gap between two walkable areas, but the agents sometimes don't take the link at all (no matter their radius) or just after a few seconds of not moving. also a weird thing: the navmeshlink doesn't show up in the editor if i pick the correct values (x and z start and end 0, only y start and end differ, if i click align transform, it sets z values to -0.05), but it still works (as above, only sometimes).
    any explanations of this? did i configure something wrongly? i tried it with several agent sizes but they keep stopping occasionally and also seem to have problems steering around obstacles and other agents
     
  8. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
  9. SomeRandomGuy

    SomeRandomGuy

    Joined:
    Jul 4, 2012
    Posts:
    11
    @MelvMay In reply to #152, has there been any work done to make 2D Navmesh work yet since september is coming to a close? I'm making a topdown 2D game with a friend, and was super excited when I remembered the navmesh system existed as it would make the whole thing that much easier to code. Seeing workarounds exist is great, but if it's going to be supported out of the box soon I may hold off on pathfinding for now and put my efforts elsewhere for a while. Thanks in advance! :)
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    2,051
    I'm personally not working on it but last week I did ask the dev (who was scheduled to work on it end of Sept) said they should be able to after Unite (which was last week). As always, don't hold-up your development because a feature might be coming in the future.
     
  11. SomeRandomGuy

    SomeRandomGuy

    Joined:
    Jul 4, 2012
    Posts:
    11
    Aye, nice to know it may be coming soon then! We're making the game mostly as a little hobby project so hold-ups aren't too bad. Probably going to depend on how soon we finish other stuff, but if we do get stuck because of it we'll definitely follow your advise and just go with one of the workarounds out there, that's not a problem. Thanks for the quick response! :D
     
    Mohave_j likes this.
  12. Ocean257

    Ocean257

    Joined:
    Jan 9, 2016
    Posts:
    13
    I want to bake at runtime as my map is procedurally .
    Is there any way to do it?

    EDIT ::
    NaveMeshSurface2d has function called BuildNavmesh() Which did my job
     
    Last edited: Oct 22, 2019
    vhman likes this.
  13. Ocean257

    Ocean257

    Joined:
    Jan 9, 2016
    Posts:
    13
    Navmesh Modifier only works when it is added to a component which has Renderer component in it
    It does not work for the component which has colliders.
    Is there any way where it works when the navmesh modifier component is added to colliders?
     
  14. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
    DungDajHjep likes this.
  15. kubci98

    kubci98

    Joined:
    Mar 15, 2013
    Posts:
    2
    Hi,
    is it possible to make NavMeshPlus work with non-grid colliders as well? (for instance having a Walls object with a composite collider) I need to have some obstacles in rotated or otherwise not fitting the grid, but even though I attach the NavMeshModifier component to any other game object (with both a BoxCollider2D and SpriteRenderer), it never actually modifies the navmesh. If it is possible, is it already implemented and I am doing something wrong, or if not, do you have any hints on how to implement this?

    Thanks
     
  16. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    107
    Hi @kubci98,

    Yes its possible to use non-tile based objects for navmesh.
    Almost all code is moved to this single file https://github.com/h8man/NavMeshPlus/blob/master/NavMeshComponents/Scripts/NavMeshBuilder2d.cs

    As you can see:
    Code (CSharp):
    1. foreach (var modifier in grid.GetComponentsInChildren<NavMeshModifier>())
    It will collect all sources under first grid object it will find.
    So you can put all your obstacles into grid object (as child), it will not interfere with tile-map, but will be counted as a source for navmesh.

    Feature UnityEngine.AI.CollectObjects is not implemented in navmeshplus
     
  17. kubci98

    kubci98

    Joined:
    Mar 15, 2013
    Posts:
    2
    Awesome, thank you for this.