Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

path finding in Unity3d 2D game.

Discussion in '2D' started by icemedia, Jul 8, 2014.

  1. icemedia

    icemedia

    Joined:
    Jul 8, 2014
    Posts:
    10
    Hi Dears,

    sorry but I really got stuck in a 2d tower defense game.
    I'm using Unity 4.5 with it's new 2d feature, I searched 2d path finding everywhere and can't find good solution.
    unity3d navemesh? no, no x-y plan supported.
    A* pathfinding? no, didn't find 2d support too.
    could anyone here help me out here?

    Thanks
    Leo
     
  2. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Well, If its only tower defense, then i would suggest to use coroutines.
     
  3. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    i think i seen something somewhere where people were using "Beacons" You drop 2 empty game objects and move the AI to one or the other and back and forth...
     
  4. icemedia

    icemedia

    Joined:
    Jul 8, 2014
    Posts:
    10
    thank you Rutenis, is Corutines a way of multithread in C#? how can I use it in a 2D tower defense for pathfinding?
     
  5. icemedia

    icemedia

    Joined:
    Jul 8, 2014
    Posts:
    10
    Thanks Kilrath, I googled but can't find Beacons that is 2D pathfinding related. would you let me know more ?
     
  6. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Its bassicly timing. You could easly calculate how much time it would take to change direction, in c#. :)
     
  7. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    506
  8. AgusB

    AgusB

    Joined:
    Jun 20, 2013
    Posts:
    65
    HI, I use Unity's built in pathfinding in my 2D game, as it doesn't work in XY I had to rotate everything 90 degrees including the camera, so everything looks the same but the axis are XZ, the Y being the height now (which we don't use). This way, the pathfinding works like a charm
     
  9. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  10. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
    if its for a tower defence i should use waypoints, not pathfind, mybe you would like diferente paths on the map, and set the diferent paths arbritray.
     
  11. Aedous

    Aedous

    Joined:
    Jun 20, 2009
    Posts:
    244
    You might want to try this.
    http://arongranberg.com/astar

    You don't have to flip everything to face 90 degrees like AgusB is suggesting. It may take you a day to get used to it but I managed to code my AI using this pathfinding tool with my 2D game and it's working very well!

    I suggest you read through the tutorials:
    http://arongranberg.com/astar/docs/getstarted.php

    Just pay attention to a setting that allows you to use 2D colliders instead of 3D colliders. You may also have to flip the pathfinding graph that it creates so that it matches your game.
     
  12. zedz

    zedz

    Joined:
    Aug 31, 2013
    Posts:
    229
    2d games A* is the standard method
    but as calavera saiz for something as simple as a tower defense game where the aliens follow the same path you dont need A*