Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Navigation2D Official Thread - Use Unity's built in Pathfinding for 2D Games

Discussion in 'Assets and Asset Store' started by mischa2k, Jan 4, 2017.

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Yes!
     
  2. ConnectionFaild

    ConnectionFaild

    Joined:
    Oct 5, 2016
    Posts:
    4
    Hi! I'm using unity 5.6.0f3 and sometimes lose navmesh gizmo in scene view. Can't say in wich situation it has happend before, but after I've updated nav2D to the last version I don't see gizmo at all. I tried baking/clearing in both 2d and 3d navigations in all ways - it didn't help. Can you help with this issue? I'll try to provide more information if you'll ask.

    Update: Just got gizmo again by adding new object with box collider to scene. Anyway it doesn't looks normal.)
     
    Last edited: Aug 6, 2017
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You should only see it while the Navigation2D windows is active - just like with the default Navigation system.
     
  4. ConnectionFaild

    ConnectionFaild

    Joined:
    Oct 5, 2016
    Posts:
    4
    Yea, i know that. :) Ofc i mean that gizmo is unseen even with focus on navigation2D window.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Does it happen with a fresh Navigation2D asset and Unity 2017.1 too?
     
  6. ConnectionFaild

    ConnectionFaild

    Joined:
    Oct 5, 2016
    Posts:
    4
    I didn't migrate to 2017.1 yet. Still using 5.6 ver.
    Got this gizmo dissapearance again after creating new scene. There is no static objects in the scene, just 2 agents2D. I've done baking and gizmo haven't appeared.
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Can you please try in 2017 to see if it happens there with your setup too? This way we know more. Could be a thousand things.
     
  8. ConnectionFaild

    ConnectionFaild

    Joined:
    Oct 5, 2016
    Posts:
    4
    This gizmo isn't a big problem for me right now, I mostly do scripting. I think I'll try 2017 after I'll make a stable version of my game scene. Shouldn't take more than a 2-3 weeks, I suppose. I just don't want bother myself with all transitional things right now, sorry.
     
    mischa2k likes this.
  9. Bimboleiro

    Bimboleiro

    Joined:
    Sep 24, 2015
    Posts:
    3
    I just bought your asset and I am really liking it. It is very simple and the logic easy to understand, but I am facing quite a big problem, that I do not know how to solve.

    I am making a top-down shooter (Hotline Miami-like), and I am using this asset to set the destination to all NPCS. When I use navMeshAgent2D.SetDestination(), the NPC will go to the destination as expected, but the rotation of it will not be altered, so it will permanently look at the same direction no matter which destination I set.

    I hope it is clear enough. English is not my mother tongue.

    Thanks in advance! :)

    Edit: My version of Unity is 5.6.2f1
     
  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Oh, didn't know that this was necessary. I always used different sprites to indicate the direction.
    I think even in Hotline Miami the rotation is based on where you move your cursor, not where you move. Are you sure you need this feature?
     
  11. Bimboleiro

    Bimboleiro

    Joined:
    Sep 24, 2015
    Posts:
    3
    screenshot2.png
    Thank you for your quick response.

    I am not moving my player with the Navigation system you provide. I am only moving my NPCS with this 2DNav System.
    The rotation of the player is not a problem, it works good. The problem is the rotation of the NPCS, since they are the ones being "moved" by the 2DNavSystem. Maybe I explained myself poorly in the previous post, so I will try to be more explanatory here.

    When I set the destination of an NPC, the NPC will reach his destination, no problem at all. No matter how many corners he has to take in order to arrive to the point. Everything perfect. The problem comes with the rotation of the NPC. This NPC will never face the direction he is currently walking towards. I set a destination and the NPC will stick to the previous rotation it had before this new destination was set. It will not react to corners or anything. It just does not rotate.

    I have tried making the NPC look at the first corner, then when he arrives to that first corner, look at the next one, etc... (until he reaches his destination).... no luck
    I have tried to somehow check my previous position every frame and compare it with my current position, so I can obtain the direction the NPC is walking, and by doing so, I can set my NPC to face that direction (by transform.up = direction)... no luck either.

    I guess my question is, how is everybody else handling this rotation problem?
    Is there a way that I can get the direction my navMesh Agent is currently moving towards?

    My NPCs have a flashlight that is always pointing to the green transform arrow (transform.up).
    How can I make the transform.up of my NPCS point to the direction that the NPC is currently walking to? If there is no obstacle, I can directly set them to look at the destination. But I cannot do that when there is an obstacle in between the NPC and the destination.

    Thank you very much
     
    Last edited: Aug 21, 2017
  12. Bimboleiro

    Bimboleiro

    Joined:
    Sep 24, 2015
    Posts:
    3
    I guess it is a matter of making NPC's rotate on the z axis, so that transform.up is always pointing at the direction the NPC is moving towards.

    I would really appreciate if someone could give me a hint on this one.
     
  13. Iliatar

    Iliatar

    Joined:
    Sep 10, 2017
    Posts:
    1
    Hi, vis2k!
    Sorry for my english.
    Today I have install your Nav2d and use it in my top-down project.
    After first start Agent have not correctly move to destination point - it didn't avoid obstacles.
    I have explore your code and discover, that for created NavMeshObstacles "carve" property is set to "false" (in "NavMeshObstacle2D" script, at string 11, and there is Developer comment "experimental and hard to debug in 2D").
    I have change it property to "true", and after that Agent starts to avoid obstacles.
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out NavMeshAgent2D.cs - you can use the 3D agent's transform.forward via NavMeshAgent2D.agent.transform.forward.

    Yes, feel free to change it to true!
     
  15. kaniballo

    kaniballo

    Joined:
    Sep 2, 2013
    Posts:
    8
    Hi @vis2k can you Navigation 2D be used together with Behavior Designer - Movement Pack from Opsive?
    Tnx in Advance.
     
  16. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I never tried that.
     
  17. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21
    Hey. Navigation2D doesn't show up in the "Window" menu for me, and none of the components show either.
     
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Maybe restart Unity?
     
  19. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21
    Tried that. It didn't work.
     
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Do other editor extensions work?
     
  21. Bambivalent

    Bambivalent

    Joined:
    Jan 25, 2017
    Posts:
    16
    Does Navigation2D work in 2.5D sidescrollers/platformers, i.e. a game with 3D objects which move in x/y direction only?
     
  22. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    No
     
  23. maddieScarbrough

    maddieScarbrough

    Joined:
    Sep 7, 2016
    Posts:
    21
    Updated Unity to 2017.1. After that, it worked just fine. Thanks!
     
  24. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update:
    • V1.24
      • Upgraded to Unity 2017.2.0p2
      • TilemapCollider2D support added. Works perfectly fine with Unity's new Tilemap feature now.
     
  25. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi vis2k
    Have just downloaded Navigation2D. Amazed at how easy it was to drop into my project! My code had previously been using RigidBody2D's: a couple of lines deleted and a few rerouted through NavMeshAgent2D and Bob was well and truly, my Uncle! Impressive. :)

    I do have a couple of questions that maybe you could help with - from having had a quick play around with colliders and baking, it would seem that:-
    1. Collision objects are recognised by the baking process only if they are both a) static and b) in root level GameObjects. Even making their root object static does not help.
    2. There may be a maximum number of elements for a polygon collider to bake correctly?
    For point 1, this will cause clutter at the top level - is there any way to organise colliders to remove the need to have them all at the top level?

    For both points 1 and 2, I am using the handy Tiled Map Editor to generate the game world. The collision data is stored within that editor (generated automatically directly from 'world' objects) and imports into Unity in a logical hierarchy. One polygon collider, for example, has generated 23 paths each with up to 300 elements. These colliders are not being observed by the NavMeshAgents, but a smaller test polygon collider, placed at the root level, works fine.

    Would appreciate your thoughts.
    Thanks.
     
  26. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    1.) I am not 100% sure what you mean. Can it be reproduced in the demo scene?
    2.) do you mean maximum amount of edges in the polygon or what do you mean?
     
    Doug_B likes this.
  27. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    1. It is not reproducible in the demo scene. Clearly a bit more head scratching required on my part.
    2. If there is no limit on the number of elements in the polygon collider then it must just be related to the previous point.
    Thanks for the suggestion. :)
     
    mischa2k likes this.
  28. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi again vis2k,
    Ok, now I can reproduce the problem in the demo scene. Here are the clarifications of my 2 points above:
    1. For some reason, when I was parenting my test polygon collider in my own scene, somehow a weird scaling was being applied / removed as I parented / un-parented my test object. So, in fact, this object was working all along (the same as in the demo scene) but was just really small in one configuration. I therefore, mistakenly thought it was not working. So this point is resolved - my mistake.
    2. The problem here is with the polygon collider and can be reproduced in the demo scene (see screenshot). The first path can have as many elements as you like, I guess. However, all subsequent paths (i.e. Element 1 upwards) seem to be ignored. You can see that I have simply split the polygon collider into 2 paths that should yield roughly the same result as the unedited demo scene. I guess the baking only works for one path (Element 0)? :-
    Navigation2D_Multiple_Elements.png
     
  29. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I recommend using two colliders instead. Triangulating 'two' polygons will be weird otherwise.
     
  30. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hmm, that really is not a desirable option. As mentioned, I am using the Tiled Map Editor. It auto generates the collision data directly from the map in this format. That solution would mean I now need to trace out all my collision data again - but this time by hand!

    Just to try and understand, why are these 2 situation different? :-
    1. PolygonPathA inside Polygon Collider 1 / PolyonPathB inside Polygon Collider 2
    2. PolygonPathA and PolygonPathB inside Polygon collider 1
    They both yield the exact same result. It is just the way the (exact same) data is stored.

    Not sure if this helps or not, but just to add, the gap in my example is purely the way I created that test. In the data from the Tiled Map Editor, there are no gaps between Paths in the same Polygon Collider.
     
  31. Cykid

    Cykid

    Joined:
    Aug 10, 2016
    Posts:
    2
    Is it possible to get the Z rotation of the movement?
     
  32. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Might be worth trying out Unity's new built in Tilemap feature. That definitely works with navigation2D. I can also issue a refund if needed.

    You could use the projected 3D agent's Y rotation for that
     
  33. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi vis2k,
    I noticed that Unity had a tilemap feature but haven't had a chance to take a look at it.
    In the end I put in a series of rough outlines which worked so far as there is currently only one map.
    No need for a refund- this is the only issue that I have found with the software. But thank you for the offer.
    Cheers,
    Doug.
     
  34. Cykid

    Cykid

    Joined:
    Aug 10, 2016
    Posts:
    2
    Thanks for your fast reply!
    I was trying to do that but the top and down direction looks mirrored... i dont know how to change that

    transform.rotation = Quaternion.Euler (0,0,GetComponent<NavMeshAgent2D>().agent.transform.rotation.eulerAngles.y);
     
  35. MartinMouritzen

    MartinMouritzen

    Joined:
    Jul 3, 2017
    Posts:
    9
    I'd love to see how you did this, even the not so clean version, as I'm having the same problems, and haven't got it working 100%.
     
  36. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can use a joystick with the navmeshagent too, just set agent.destination to something like transform.position + Vector3.up * Input.GetAxis(Vertical) etc.
     
  37. MartinMouritzen

    MartinMouritzen

    Joined:
    Jul 3, 2017
    Posts:
    9
    vis2k: Interesting. I'll try that :)
     
  38. MartinMouritzen

    MartinMouritzen

    Joined:
    Jul 3, 2017
    Posts:
    9
    Hi Vis2k,

    I managed to get it to work.

    I do have a completely different question though. My characters seem to get stuck on corners a lot, and then the "stopped agent because of collision in 2D plane" comes and they give up.

    Mostly it's if near the object they have to move around in the first place. When starting from further away they can manage to go around it. - Is there any way to improve this?
     
  39. MartinMouritzen

    MartinMouritzen

    Joined:
    Jul 3, 2017
    Posts:
    9
    Okay, to clarify a bit on my above message.

    It's only if I set agent radius below 0.1. And then I get a "The NavMesh may not be generated properly as the ratio between Agent size and voxel size is large. Try setting voxel size to larger than 0.019"

    So when it's at 0.1 it works. But then the problem is that the agent doesn't really want to go completely near the objects (which seems a bit weird in my game, because it's pixel art). Is this just something I will have to learn to live with, or can it be helped?
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Probably need to live with it for now, sorry. It's really just using the built-in 3D system and projecting it to 2D. It's not 100% pixel perfect.
     
  41. MartinMouritzen

    MartinMouritzen

    Joined:
    Jul 3, 2017
    Posts:
    9
    Okay, thanks for the reply! :)
     
  42. Hazlo

    Hazlo

    Joined:
    Feb 22, 2014
    Posts:
    11
    Hi! I I'm trying to use Navigation2D with SuperTileMapEditor, but it doesn't seem to work because STME uses EdgeCollider2D. Would it be possible to add support for such colliders? It would be great to make Navigation2D compatible with the most important tilemap asset in the store :) Thanks in advance!
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I was secretly waiting to see if anyone even needs that. Good to know, will put it on my ToDo list.
     
  44. Hazlo

    Hazlo

    Joined:
    Feb 22, 2014
    Posts:
    11
    Hehehe That would be great! Thank you!
     
    mischa2k likes this.
  45. Hazlo

    Hazlo

    Joined:
    Feb 22, 2014
    Posts:
    11
    Hello again. I've been trying to make up for a temporary solution until EdgeCollider2D support eventually arrives, and I've switched to using Polygon2D colliders. But I've found that the navmesh baking seems not to work fine with polygons that have non-fully-convex shapes, like an "U" or a "C". It seems to only take into account the inside lines and not the exterior ones, which is really an inconvenience. Am I doing something wrong, or is it a limitation from Navigation2D? Thank you inadvance!
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    My triangulation algorithm isn't perfect, that's probably the reason.
    Not sure if the built in system even would work with that in 3D.
     
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: EdgeCollider2D will be in the next version V1.27. Should be on the asset store in the next couple of days!
     
    Hazlo likes this.
  48. Hazlo

    Hazlo

    Joined:
    Feb 22, 2014
    Posts:
    11
    Great! Thank you very much!
     
    mischa2k likes this.
  49. Hazlo

    Hazlo

    Joined:
    Feb 22, 2014
    Posts:
    11
    I've been testing EdgeCollider2D support in version v1.27 and it seems to work perfectly. So by now I'll go on building my project with Navigation2D and Super TileMap Editor working together. I think both products can now feel
    strengthened with this advance, and that's really good news. I'll continue doing tests and then write a review explaining this. Thanks again for your support, vis2k. I'm still laughing when I remember your sentence "I was secretly waiting to see if anyone even needs that" :D
     
    mischa2k likes this.
  50. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Great to hear. I guess Navigation2D is complete now. Looking forward to your review!