Search Unity

2D pathfinding

Discussion in '2D' started by Gureen_Ryuu, Nov 21, 2013.

  1. Gureen_Ryuu

    Gureen_Ryuu

    Joined:
    Oct 27, 2013
    Posts:
    8
    I realize that Unity2D has just been released, but I want to ask if there's any solutions to pathfinding and navigation that can be used for it? I tried Aron's A* plugin, but it doesn't seem to work with 2D colliders, just 3D ones.

    I don't know if I should use a mix of 2D and 3D colliders and how efficient that will be.. (2D for physics and 3D for the pathfinding) or if there is an upcoming plugin for that.
     
  2. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    That is something I was wondering as well. I really think that they should make possible to user navmesh with the 2D system in a convinient way
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    By 2D pathfinding do you mean platform game style or top down? top down is trivial with http://arongranberg.com/astar/ or navmesh. 2D Platform game pathfinding is by large not necessary. It becomes really necessary when you have island situations and things like that, and A* isn't the sole solution, but more of a check for an opening.
     
  4. Gureen_Ryuu

    Gureen_Ryuu

    Joined:
    Oct 27, 2013
    Posts:
    8
    It's top down 2D. But as I mentioned, Aron's A* isn't working with 2D colliders. :(
     
  5. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
  6. Gureen_Ryuu

    Gureen_Ryuu

    Joined:
    Oct 27, 2013
    Posts:
    8
    I haven't used unity in a while, and never got around to Navmeshes. Is it still an pro only solution, since I have the free version.

    Also, will it enable group pathfinding that's available in Aron's A*? I know it works with colliders, but I don't know if it will work with a nav mesh to allow avoiding dynamic obstacles.
     
    Last edited: Nov 22, 2013
  7. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    could use 2d ray casting to detect 2d Colliders, and just do some simple collision avoidance, like "if ( I'm about to hit wall) { avoid it }" kind of thing...
     
  8. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Just fyi (I know the post is a few weeks old). The A* Pathfinding Project now supports 2D colliders when using grid graphs.
     
  9. Jeronimous

    Jeronimous

    Joined:
    Jan 8, 2014
    Posts:
    2
    I find this thread to be most helpful. Thank you all!
     
  10. westykid

    westykid

    Joined:
    Jan 12, 2014
    Posts:
    1
    Hey guys, just jumping in with more questions (i figure that's the right thing to do right? rather than start a new thread for the same topic?)

    I'm working on a point and click adventure game and I've kinda hit a wall with the code, so far I have a ray from the mouse checking if you've clicked on the floor collider then using the Vec2 position as an iTween.MoveTo position (i can share the code if anyone's interested).

    Works great so far but as the level is a flat sprite and any form is merely 'suggested' it won't necessarily have colliders/gaps in the way for an engine to use. I was thinking i'd probably have to overlay a series of polygons over it to map out the ok areas by hand. Anyone got any other thoughts?
    $Screen Shot 2014-01-12 at 19.25.30.png
     
  11. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Actually this is something of how I wanted to do it for my Adventure Game Framework as well (sig if interested). So I've made up a pathfinding package as standalone since it might find other uses as well, you can see it here if you like:
    http://forum.unity3d.com/threads/224962-Poly-Nav-Pathfinding-for-4-3-2D

    Sorry if this sounded like a shameless promotion..
     
  12. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    I want A* path finding algorithm for my 2d game. I have read about NevMesh but it doesn't work for 2d game. If you guys have implementation of A* algorithm for 2d game then please share it.
     
  13. NelsonPunch

    NelsonPunch

    Joined:
    Apr 21, 2014
    Posts:
    6
    Maybe this can help
     
  14. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
  15. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  16. tonycoculuzzi

    tonycoculuzzi

    Joined:
    Jun 2, 2011
    Posts:
    301
    Is there planned support for 2D colliders taken into account in the RecastGraph?
     
  17. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    355
  18. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    I found the easiest solution was simply to manage/update a 2D array in the code (very easy to do if you're using a tilemap) and have the A* Pathfinding base everything off the array. No need for Unity itself to do anything at all.

    Very efficient too - updating an array costs barely nothing at all.

    (Obviously the sequence of when objects update the array needs to be done with some careful thought, to avoid units physically moving into/through nodes too soon).
     
    Last edited: Dec 22, 2018
  19. AAManiqueH

    AAManiqueH

    Joined:
    Apr 29, 2020
    Posts:
    3
    Hellow guys, i have an issue
    I saw the youtube video of Brackerys about pathfinding, it works well but just for region or space
    upload_2020-4-28_22-6-51.png
    The space between the red lines is where the pathfinding method works well, if the enemy is out of the red line
    their pathfinding component makes him to return to the line and not to follow my playable character
    Between the red lines the enemys follows the playable charater well
    I dont know what this could be, please help with this topic
    If need it i will show the code

    Thanks guys