Search Unity

Can 2d games use the Navigation Mesh

Discussion in '2D' started by Tainted_Lemon, Nov 16, 2013.

  1. Tainted_Lemon

    Tainted_Lemon

    Joined:
    Aug 25, 2013
    Posts:
    5
    Hi,

    It seems that the navigation mesh is bound to the x-z axis while the new 2d physics and rendering is performed on the x-y axis. Are they completely incompatible?

    Thanks
     
    juanitogan and frekiidoochmanz like this.
  2. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    142
    A very important question. I too would like to know how we can get around this.
     
  3. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    I agree, this is the biggest thing holding us back from switching right now.
    What I'd really like to see to an option to turn the whole 2D system to work on XZ instead of XY. Then we don't have to recode and remake every asset in our top-down game in order to transition to the new system. It also fixes the NavMesh issue.
    I should also note that behaviour such as LookAt doesn't work properly in XY. The ability would go XZ would again fix this.
     
    Last edited: Nov 23, 2013
    badlog likes this.
  4. noethis

    noethis

    Joined:
    Nov 11, 2013
    Posts:
    129
    Agree--would be really nice to be able to switch Unity2D to XZ for top-down games. I'm currently working in 3D so I can have pathfinding.
     
  5. Flickayy

    Flickayy

    Joined:
    Jan 20, 2013
    Posts:
    40
    This is exactly the feature that should be implemented, either that or some way to do 2D navigation.

    Unless there is already a work around that I've completely missed...
     
  6. Haxxxxx

    Haxxxxx

    Joined:
    Jan 7, 2014
    Posts:
    1
    Hi there, quick question:

    What is the current method of performing navigation in 2D top down game development in Unity, could someone point me in the right direction?

    (I have googled it)
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Think it's a great idea.
     
  8. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    Maybe I am missing something here but I don't see where the problem is. Since 2d only uses two dimensions, where does it matter which ones you use? Its an just a visual abstraction anyway ("down" is always toward the enemy gates). If you really need to the 3d navmesh for a 2d game (which seems a bit overkill), whats wrong with simply rotating the camera and assets? And I don't see how LookAt would be "fixed" as with 2d your camera is always going to always be perpendicular to the viewing plane. Rotating in any direction around the relative "z" is 3d, not 2d.

    Also, why would you have to rebuild/recode all your assets? If the game already is coded and built, why redo it? Most the new 2d features are to ease production, none are really "new". What benefit would there be to redoing everything?
     
  9. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    What's overkill about wanting pathfinding in a 2D game, exactly?



    Box2D only works in XY.

    Most of the methods like this manipulate transform.forward. In pure XY, transform.forward is meaningless (it is not related to any visible direction of an object), so any such methods must be redone manually assuming transform.up is actually the forward direction of the transform instead.

    No it's not. Z is just a letter. If I have two letters representing a graph, one of them is X (representing what appears to be "horizontal" and the other is Z (what appears "vertical" on the graph), I still only have two possible dimensions.


    Box2D is a huge performance benefit to 2D games. For us, it means the difference between mobile platform targets and not.

    Anyway, we've just sort of accepted it, and been converting everything over the past month. It's a lot of work but 80% done now. Moved to AAron's Astar implementation for pathfinding. My main issue now is that there are giant game-breaking bugs in the Box2D implementation that need to be fixed before moving forward.
     
    Last edited: Jan 15, 2014
  10. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    As fas as I know there's currently no way to do it. NavMesh works on the XZ plane, while Unity's 2D mode is XY.

    An alternative would be to look at the other pathfinding solutions on the Asset Store, since most of them support any orientation.
     
  11. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    *bump* I'd also like to see this be integrated into future versions for any top-down (or similiar) games.
    A 2D navmesh implementation would really be awesome. :)
     
  12. Malarhak

    Malarhak

    Joined:
    Apr 17, 2011
    Posts:
    21
    Bump too. For both the pathfinding and the fact that LookAt has a weird behavior when using XY axis
     
  13. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    For a quick fix I made a Gameobject use look at and made the sprite a rotated subobject so that the direction fits the XY plane. I would not recommend this for anything final or other than testing, though. It's a very hack-ey quick solution ;)
     
  14. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Just to add my 2 cents... I think there could have an option to simply swap the z by the y axis but keeping some functionality (perhaps as an option) so you could use box2d and navmesh and stuff like dragging and dropping sprites (only works when you're in 2d mode (x+y).

    Imho it's much easier to work with x&y for 2d but when talking about 3d, it just doesn't make sense in my head that the y axis is the vertical one, I know some 3d packages like maya have this same approach but it doesn't make much sense to me because besides I'm extremely used to z being the vertical axis, in things like topology and stuff the z is always the vertical, the only exception I know they use the y as the vertical axis is in cinema because generally the thing is relative to the camera and stuff, and in this case it does make sense that the z axis for a camera is the axis going in the direction the camera is facing, but in a 'global' approach, the z axis should be the vertical imho.

    It's a real pain in the bit to use most 3d modellers and Unity.
     
  15. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    Is there any update on if/when we'll get a native 2D pathfinding solution in Unity? (for top-down games using 2D sprites and Box2D physics)

    Also, are there any plans to implement the ability to generate NavMeshes at run-time? (for procedurally generated levels)
     
  16. Ilingis

    Ilingis

    Joined:
    Dec 13, 2012
    Posts:
    63
    Bump. Anyone knows if a feature that turns XY/XZ axis is coming in 4.6?
     
  17. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    In a few official threads about feature wishes this topic came up and I think Graham (?) loosely said that 2D pathfinding is in the works and will be an upcoming thing in some version somehwere down the road. No timeframe given.

    From what I understand it will be coming some day. Until then if time is pressing maybe you want to look as one of the pathfinding solutions on the Asset Store. Some have a free release with less features but it might just be enough for your project?
     
  18. bmkorkut

    bmkorkut

    Joined:
    May 14, 2014
    Posts:
    1
  19. Artifactx

    Artifactx

    Joined:
    Jul 20, 2012
    Posts:
    14
    Here is a tutorial, that shows you how to use the NavMesh system with 2D sprites, if you are interested.

     
  20. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    @Artifactx Its a cool idea, but the methodology creates quite a bit of mess under the hood.
     
  21. tonycoculuzzi

    tonycoculuzzi

    Joined:
    Jun 2, 2011
    Posts:
    301
    Any new news on this yet? I know it has been brought up by Unity staff members a few times, but not much was said about it.
     
  22. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    http://arongranberg.com/astar/

    Aron Granberg's A Star Pathfinding Project (it has a free version) supports 2D Collider casting when using Grid Graphs so its viable for 2D games.
     
    Ash-Blue likes this.
  23. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Still in the works, it seems ...
    It will come but it takes time. The ongoing development and bughunting of Unity 5 doesn't speed this up any further, I guess. If time is critical take a look at other solutions like A* as Fenrisul suggested.
     
  24. awplays49

    awplays49

    Joined:
    Nov 9, 2014
    Posts:
    36

    That wouldn't work because mouse position is based on xy. Things wouldn't work if that happened.
     
  25. Anxo

    Anxo

    Joined:
    Jan 7, 2014
    Posts:
    13
    You can very quickly say mouse y is z. Agree, XZ switch would be awesome. Thankfully, I cought this very early and ended up switching everything to 3d physics and rotating all my assets before they became too many. But this means I can no longer use some of the cool new physics features that come with 2D physics in the game.
     
  26. TheArchitect485

    TheArchitect485

    Joined:
    Aug 5, 2015
    Posts:
    7
    Using the 3d navmesh is not overkill because its a 2d mesh overlaid on 3d objects. And the reason you cant switch to x z in unity 2d is because all the 2d tools are centered around x y
     
  27. Grimngor

    Grimngor

    Joined:
    Oct 5, 2011
    Posts:
    4
    Ok, it's 2016, do we have any updates on this? Any workaround?
     
    juanitogan, jvkies and Ash-Blue like this.
  28. hexagonius

    hexagonius

    Joined:
    Mar 26, 2013
    Posts:
    98
    Good point. We just recently ran into that restriction. Changing axis and using NavMesh with 2D would be awesome
     
  29. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No, but Unity is working on it. Alternatively, use XZ plane or 3rd party.
     
    Ash-Blue likes this.
  30. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    I've heard this will be doable with the new NavMesh API, although I have yet to see an official announcement. See here for projected timeline. Looking like a June release as of writing this comment.

    https://unity3d.com/unity/roadmap
     
  31. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194


    I made a simple pathfinding solution, designed for hordes but could work as long as you only have a few factions in your game. I keep meaning to improve it but could release it cheap on the asset store if there is any demand?

    How much would you pay for a simple 2d pathfinding solution?
     
  32. Ilingis

    Ilingis

    Joined:
    Dec 13, 2012
    Posts:
    63
    Sorry, but nothing. This really needs to be implemented in the Unity.
     
    frekiidoochmanz and Ash-Blue like this.
  33. OleksandrMartysh

    OleksandrMartysh

    Joined:
    Dec 13, 2015
    Posts:
    25
    Yep, i would pay nothing, sorry.
    I wonder why it is not implemented in Unity yet. it is really easy for such great developers like Unity programmers. It is just a question of replacing Y by Z.

    I really can't wait anymore. I need this!!!!
     
  34. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Since it's taking so long I assume it's not as easy as simply "replacing Y by Z". Also - don't hold your breath. It's been in the works for years now. If you need something now use one of the A* or other packages from the asset store.
     
  35. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    @Arowx Several solutions have already been released, but they've all failed to deliver the proper tools and features Unity's native pathfinding system already has. Not saying your tool isn't amazing, just that the 2D community is really frustrated over the lack of a solid 2D NavMesh. A lot of us have forked over $100+ on 2D pathfinding store assets. Only to find they're buggy, deprecated, and/or abandoned shortly after their release. So people here are right to complain that they don't want to fork over $$$ for another 3rd party solution and Unity should support this natively (which is in the works). You could release your package, but it might end up being deprecated as soon as 5.5 hits the shelves.

    That said your library looks pretty cool. Quite a bit going on there and the performance looks great.
     
    juanitogan likes this.
  36. RobuProductions

    RobuProductions

    Joined:
    May 18, 2016
    Posts:
    1
    Has there been a new release that fixed this problem yet? I know this post is old.
     
  37. frekiidoochmanz

    frekiidoochmanz

    Joined:
    Feb 7, 2016
    Posts:
    158
    I've payed for a few solutions, and to be honest it wasn't worth the money. Although A* pro isn't bad at all. (pricey), I still think I would have preferred a built in solution that I could then work with. However, I'm still researching it,most people use cubes and link sprite renderer transforms on top of them, (or cylanders) it does work but its a 3D game at that point.

    See the solution will work with 3D space regardless, Unity is called Unity3D I mean its amazing they even support 2D stuff to be fair.
     
    juanitogan likes this.
  38. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Has anyone here tried Navigation2D on the Asset Store? Description says it "uses Unity's built-in Navigation system to make 2D pathfinding possible without any axis rotations." Not sure how that's possible, but it's very cheap and well-reviewed.
     
    juanitogan likes this.
  39. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    73
    I've used Poly|Nav 2D for a couple of days, and the creator is quite attentive on his support thread. I'd recommend it as a lightweight, low-cost solution. It is currently has 137 ratings and a high score.

    One nice thing about it is that it supports the equivalent of dynamic rebaking on-the-fly, so if things change at runtime all paths are automatically re-calculated.

    It does have a few warts:
    • It doesn't use the physics engine at all, which may be problematic depending on what you trying to do.
    • It's agent-avoidance methodology is a bit of a hack.
    • It does not use a grid-based system, so if you are using a game built on a inviolable lattice, it really isn't going to suit your needs.
    • It currently does not support circular colliders, but it supports complex polygonal ones.
    • Currently it doesn't support agents of different "widths," meaning that if you want to have a skinny guy and a fat guy with the fat guy unable to go through a thin alley that the skinny guy can go through, then that isn't supported right now.
    • Similarly, it does not support agent-specific obstacles. Everything is either an obstacle for all agents using the AI or not an obstacle for any.
    • Currently the equivalent of the NavMesh is implemented a singleton.

    The last 3 points may be addressed in a future release.
     
  40. maewionn

    maewionn

    Joined:
    Jan 18, 2016
    Posts:
    38
    Bumping as I still have to see an implementation of this. Come on Unity, this thread alone was started 3 years ago!
     
  41. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    What about the development branch -> https://forum.unity3d.com/threads/welcome-new-navmesh-features-experimental-preview.438991/

    Which has the a "Bake NavMesh on a surface for any orientation" feature.

    But It looks like you will need to use lower level API calls for it to work in 2D, based on my reading of this post -> https://forum.unity3d.com/threads/w...res-experimental-preview.438991/#post-2839351

    So the new API calls should be in the 5.6 beta.
     
    Last edited: Jan 19, 2017
    Ash-Blue likes this.
  42. maewionn

    maewionn

    Joined:
    Jan 18, 2016
    Posts:
    38
    Huh, interesting and awesome. Thanks a lot, Arowx! Thanks to you, peopleclicking on the first sugesstions in Google will find this, too :D
     
  43. kidsanaj

    kidsanaj

    Joined:
    Jun 14, 2017
    Posts:
    2
  44. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    With the new NavMesh building components introduced in Unity 5.6 you can now build NavMeshes for any kind of orientation imaginable (2D, 3D, etc.) since they are now just components you attach to transforms, which can then be aligned with any axis you want. The only catch is these components aren't included in the standard Unity install and must be downloaded separately from GitHub if you want to use them.

    @kidsanaj
     
  45. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    Uuh. Nice. I did not know about these!
    Is it know whether they are planned to be incorporated into Unity at some point?
     
  46. Galanopoulos

    Galanopoulos

    Joined:
    Aug 2, 2017
    Posts:
    2
    Just used it to generate a navmesh on a 2D project and nothing happened. No 2D was generated...
     
  47. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    359
    juanitogan likes this.
  48. juanitogan

    juanitogan

    Joined:
    Aug 18, 2017
    Posts:
    27
    Chasing down what vhman said above, there is more chatter on this here:

    https://forum.unity.com/threads/2d-navmesh-pathfinding.503596/
    https://github.com/Unity-Technologies/NavMeshComponents/issues/102

    vhman's tool (from the previous post) appears to have the lead for tile-based worlds:
    https://github.com/h8man/NavMeshPlus

    For either tiled or non-tiled 2D worlds, Sharlatan's tool has worked for me with non-tiled colliders (it could use some basic setup hints about adding a rotated plane and a mesh renderer, and I had to rewrite some of it to run on 2017.4):
    https://github.com/SharlatanY/NavMeshSurface2DBaker

    The GitHub conversation about issue 102 points to this other WIP:
    https://github.com/Wokarol/NavMesh2D

    The Navigation2D asset appears like it doesn't work with concave polys. (NavMeshSurface2DBaker, above, works with concave polys.)

    A* Pathfinding Project appears to support 2D on only grid graphs -- which looks pretty limited to me with an overly-busy number of nodes.
     
    vhman likes this.