Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

2D NavMesh PathFinding......

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

  1. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    I have a weird issue trying to define walk paths for NPCs so I set the default action to Non-Walkable and then defined the walk paths shown below. When I start my game there are spawn points and they get spawned in at the start of the arrows but then for some reason teleport to the end.

    Any ideas why this might be happening? I'm not sure if a non closed loop pathing has been tested or not and this would be considered a pretty odd shape I'm sure.

    Edit: So I've placed some nav points in the areas that get teleported away from and they seem to path fine after instantiation. There's just something definitely going on with how the agent finds the closest nav point to attach to when instantiating in. I tried instantiating agents all over the top right horizontal path and they all instantly flashed on the path but then teleported elsewhere.

    Ok this seems to be a Unity specific problem apologies. I set the agent updatePosition to false in awake and then waited some frames before setting updatePosition back to true and it teleports correctly to a nearby path position if it is off the path and works correctly. It also fixed spawning agents correctly on a path and not teleporting randomly.

    Feel like I also had to use agent.Warp(transform.position) after Instantiation and before SetDestination was used..


    Photoshop_Fne2vC5kVy.png
     
    Last edited: Mar 26, 2019
  2. TSabos

    TSabos

    Joined:
    Mar 8, 2015
    Posts:
    90
    What are the performance implications of using this system for runtime spawned trees for a Rust style game that use NavMeshObstacle (talking 200-300 items)? I think that's an important note that this system "can" be used for 2D Colliders if they are not baked into the navmesh if you use obstacles and the Carving feature, but they have to be defined as capsule or box.
     
  3. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi,

    I'm not a game dev, and not Unity expert, and didn't made benchmarks, and navmesh is unity core feature. I made proof of concept, and still it is not a production code, and unity does not treat navmeshcomponents as production))) So it is up to you to find out and leave a feedback.

    But 200-300 navmesh obstacles with carving of static objects is not a problem. As I believe.

    All I can tell that 10k tiles is in milliseconds deal. And I'm glad to hear your findings.
     
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    TSabos likes this.
  5. AmbroseFurback

    AmbroseFurback

    Joined:
    Feb 20, 2013
    Posts:
    10
    This asset works great, thanks!

    I'm trying to learn how to move my agents. I got one that pretty much works great at seeking out a target by doing an agent.destination call. I'm trying to make one that just moves in a set direction until it hits a boundary but I'm not doing well. Can anyone point me at an example or docs that might help? Thanks.
     
  6. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi,

    If you are looking for collision event, I think its very straight forward to use composite collider on tilemap and other collider on agent.

    And if you just want to stay in programmed polygonal boundaries, just create a polygon collider and cast it against collider on agent.
     
  7. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi All,

    Just to confirm, it works with 2019.1
     
    TSabos likes this.
  8. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    10
    Please can you create a Layer-Based System like the Layer of the Tilemap Brush.
     
  9. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    @SuperFranTV Hi,

    Give me more details. You want have multiple navmeshes? Or to bake only the certain layer of tilemap?
    Describe what you want to achieve and I will create the ticket.
     
  10. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    10
    Hello sry for late answer, i want to bake multiple tilemaps with different z positions at the Tilemap-Component is a Variable named tile anchor -> there is a Z positon (layer based like Ground + Tree).

    Next is i need to restart unity if i create Tilemaps (two different) with much tiles, than after restart unity generates the navmesh correctly.
     
    vhman likes this.
  11. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi,

    Recently burned my CPU. But now I'm back)
    Made commit Add height override for Isometric Z as Y Tilemap, so even if tilemaps has Z value, you can set in Override Vector (1,1,0), and all will be flush.
     
  12. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Back to you @SuperFranTV,

    I'm not experienced Unity dev, so I'm in struggle to understand use cases.
    Can you share print screen or sample scene with case that is not working for you?
     
  13. Mc_Xlebyshek

    Mc_Xlebyshek

    Joined:
    May 6, 2019
    Posts:
    1
    Maybe you can use some elements of this project to update your script?
    * click *
     
  14. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    @Mc_Xlebyshek,

    Hi,

    The project has 1000+ of man-hours or more. And I have only 10h in a month)
    So navmesh plus is about mesh generation of _native_ navmesh for unity, not about AI or agents.
    While Aron Granberg does not use unity pathfinding at all. So its incompatible)

    pro version has mesh generator, nothing to add.
    The single feature I see is to export unity navmesh data to A* mavmesh. But there is nothing to do with NavmeshPlus.

    I can give you guideline how to do it if you want.
     
  15. brettsaunders

    brettsaunders

    Joined:
    Feb 28, 2019
    Posts:
    4
    upload_2019-6-1_23-24-53.png

    I have just started to work using you NavMeshPlus and just wondered if you could help me with a few things.
    Firstly I have gone into the Barrels sprite editor and set the outline as tight as possible, yet this is as close as it gets? Is it possible to improve this and how?

    Secondly what I really want to do is have the bottom 1 quarter of the barrel be the part that is not walkable so that the Agent can walk behind it as if it were actually on the floor?

    Lastly, as you can be seen in the picture I have two levels of ground, currently each is on a different tile map, but I am not sure how to go about actually making them separate levels. I was going to use physics colliders on the edges you can't walk up, but not sure if this allows that.
     
  16. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi @brettsaunders

    Hi, while colliders get better polygons, I didn't found public API to make fine triangulation out of box. So yes, it is as fine as it is. And if you talking about gap between barrel and navmesh - it is 100% fine, the gap is equal to radius of navmesh agent cylinder. So if agent 1 unit wide, you will have gap of 0.5 unit.

    Walking behind barrel is also possible, you can split barrel on two planes, or edit its outline - here

    I'm not experienced unity dev. but here is the sample

    Feel free to ask any questions.
     
    mdotstrange likes this.
  17. mdotstrange

    mdotstrange

    Joined:
    Sep 23, 2013
    Posts:
    208
    Just wanted to drop in and say thank you for making NavMeshPlus :)
     
  18. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    mdotstrange likes this.
  19. mdotstrange

    mdotstrange

    Joined:
    Sep 23, 2013
    Posts:
    208
    vhman likes this.
  20. thecodesalim

    thecodesalim

    Joined:
    Jun 19, 2019
    Posts:
    4
    Hello @vhman ,

    Please how do I make the grid size smaller? the baking size is too big.

    Thank you.
     

    Attached Files:

  21. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    @thecodesalim

    Do you mean the gaps around the walls are too large?
     
  22. thecodesalim

    thecodesalim

    Joined:
    Jun 19, 2019
    Posts:
    4
    Yes, it is too large
     
  23. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    It is controlled by NavMeshAgent; play with these fields
    upload_2019-6-19_16-56-22.png
     
  24. thecodesalim

    thecodesalim

    Joined:
    Jun 19, 2019
    Posts:
    4
    Yes, Thank you. It worked.
    I have another problem It changes the z position of my agent and the agent disappears from the tile map when I click play
     
  25. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    Code (CSharp):
    1. void Start()
    2.     {
    3.         agent = GetComponent<NavMeshAgent>();
    4.         agent.updateUpAxis = false;
    5.     }
    This might help.
     
    thecodesalim likes this.
  26. thecodesalim

    thecodesalim

    Joined:
    Jun 19, 2019
    Posts:
    4
    is it possible to bake navemsh during gameplay?
    Thank you.
     
  27. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    Look there:

     
  28. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Many thanks to @alkaitagi for help. Your answers are 100% correct.
     
  29. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    alkaitagi likes this.
  30. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    Unity are working on native 2D support for NavMesh, not limited to TileMap2d. I think we all here are super excited for this.
     
  31. cecilcruxis

    cecilcruxis

    Joined:
    Sep 17, 2013
    Posts:
    92
    I was just about to post this video when i saw the thread. Glad more people are bring attention to this.
     
  32. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    @alkaitagi

    Do you have link to CreateMesh native API that referenced in video?
     
  33. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Last edited: Jun 30, 2019
  34. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    To give some context, this was done during Hackweek last week where Unity devs get together to work in teams, often devs who don't know each other and have fun doing so. We decided to work on something that would have immediate benefit to the community, in this case the 2D community. We managed to get this working in a few days and presented it on the last day (last Friday) along with the hundreds of other projects.

    It's now Sunday and I'm back from HW and very tired. The CreateMesh/GetShapeHash native changes are fairly minimal but getting them into trunk (2019.3 alpha currently) will require a little work. Tidy-up, add tests and docs then get a PR up for review, get approval from the release managers then it'll go in. I'm super busy but if I don't do this next week then I'll never get to it so on Monday I'll start that process and should have a PR before the end of next week.

    Very confident this'll be ready for trunk by end of next week though. We do have a C# NavmeshSurface2D we created which we'll release that'll work with the alpha but you'll obviously be able to use the meshes yourself in your own code without that should you wish and drive navmesh directly.

    The CreateMesh is "Collider2D.CreateMesh()" so works with all 2D colliders so Box, Capsule, Circle, Edge, Polygon, Tilemap & Composite. It also supports the "EdgeRadius" property of Box/Edge/Composite too as well as the "Outline" mode of the Composite.

    CreateMesh also provides two args that allows you to specify whether you want the mesh baked using the body translation and/or rotation. Keeping them separate was useful in our demo and may be useful elsewhere but this was particularly useful in context of the second method 'Collider2D.GetShapeHash()' that returns a hash for the unique configuration of the collider. For example, if you have a hundreds of PolygonCollider2D placed around the scene all using the same sprite, they'll have the same hash so you can reuse the same mesh for nav and check if you've already got an appropriate mesh by (say) referencing them in a hash-table against the Mesh object.

    The only missing piece is Edge. Specifically, we supported Edge when the start/end vertices we coincident at which point we treated it as a closed area. When the start/end vertices were not coincident it didn't create a mesh (it wasn't important for our demo). However, I can change that to support Edge(Collider2D) without coincident start/end vertices but it'll only work if you're using an EdgeRadius >0 which makes sense as otherwise it has no area. Should be able to get that working Monday morning (post coffee that is).

    As above, ASAP. :)
     
    Last edited: Jun 30, 2019
    DanielThomas and vhman like this.
  35. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    73
    Hi,

    Thank you for update. We will be glad to see NavmeshSurface2D on GitHub.
    After some many years, a week is nothing))
     
  36. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    We have a pull-request to get the required native change into our repo however I will say that it still has to pass our release management approval because it is a last-minute change and cut-off is next week before we go into beta for 2019.3. If it's not allowed then it'll have to go into the next release but fingers crossed that doesn't happen.
     
    DanielThomas likes this.
  37. alkaitagi

    alkaitagi

    Joined:
    Dec 8, 2016
    Posts:
    41
    @MelvMay good to hear, look forward to trying it.
     
  38. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    10
    Hello, where can i find the source of the new NavMesh2D? Could it be possible, that the NavMesh is generated by Colliders at Runtime not by a NavMesh Modifier?
     
  39. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    Read what I said above. Give some time for us to actually get something out, we only worked on this last week during hackweek.

    That's what the video above shows.
     
  40. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    The ability to create a mesh from any 2D collider went into 2019.3.0a10 (not available yet). The follow-on NavMesh code for 2D will go on Github but that's being worked on by another dev. When I know that's up I'll post it.

    The two new methods are:
    "Collider2D.CreateMesh()" and "Collider2D.GetShapeHash()".
     
    ashapcott and vhman like this.
  41. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    ashapcott and vhman like this.
  42. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    10
    Thank you for the Information.
    Is there any date out?

    Should the NavMeshAgents be scripted to a NavMeshAgents2D, because 2d is much lighter than 3d for performance ressons?
     
  43. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,704
    No.

    No, we didn't rewrite the whole navmesh system. It was making it compatible with the existing system.


    I wanted to add that it's also peak holiday time at Unity too so the dev who'll be getting the Github C# source up is on leave this week but the native support is in as I posted above and we'll get the C# source up ASAP.
     
    Last edited: Jul 15, 2019 at 11:13 AM