A* Pathfinding

The focus for the A* Pathfinding project is to provide an out-of-the-box pathfinding system.
The system is easy to set up and it scans the surroundings automatically.

  • Terrain grid
  • Terrain Demo

    Building Demo

    Navmesh Demo

    Features

    Easy to set up
    Requires no external data or code libraries
    Very fast (see performance)
    Can use multiple grids
    3D pathfinding is supported
    Runtime changing of the grid, for example, placing a building on the ground
    Node linking
    Free for non-commercial projects (see license for info about commercial use)
    Can execute over several frames (meaning less/no lag)
    Path caching
    Path simplification
    Support for navmeshes
    Support for creating your own procedural grid generators
    Works with Unity iPhone

    Performance

    For example: A path with 168 points and which searched 316 nodes took about 0.1 seconds to complete, it was spread over 10 frames.
    Another more complicated example: A path with 156 nodes and which searched 3730 nodes took about 0.43 seconds to complete and was spread over 42 frames. These example show much longer paths than you are likely to need (in case you are not making an RTS game).
    An example which is a bit more normal goes like this: A path with 33 nodes took about 0.006 seconds to complete, it was spread over 1 frame and searched 162 nodes.

    The 2.8 beta version which has just been released is quite a lot faster though.
    For example, a path with 137 nodes and which searched 3022 nodes took 0.0036 seconds to complete.
    Compared to the example with 156 nodes on the previous system this is about 100 times faster, however that test was done on a slower computer, when I have done controlled tests on the same computer the beta was about 9-10 times faster compared to the old system (2.52).

    Results can very very much depending on computer specs and things like that, so it is hard to give a good example.
    These tests were done in the Unity editor.

    Licence

    Creative Commons License
    A* Pathfinding by Aron Granberg is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.
    If you want to use the code for commercial projects please contact me at aron.g@me.com.
    A license to use the project/code in commercial applications/games costs US $100, although other options such as profit sharing can be discussed if that suits the person/company in question better.

    Download

    Download A* Pathfinding Project version 2.5 (or version 2.8 beta)

    Documentation

    All Docs
    Get Started Guide?
    FAQ
    How do I use my code with the A* script?
    API and components
    Using Unity iPhone

    How does A* pathfinding work?

    If you have any questions or things you would want to see added to the system, please post it as a comment or write to me at aron[dot] g[at]me[dot]com.

    64 Responses to A* Pathfinding

    1. Admin says:

      Hi

      I have explained the solution for that on the FAQ page
      http://www.arongranberg.com/unity/a-pathfinding/docs/faq/

      And also on the fourth latest post in the release thread.
      http://forum.unity3d.com/viewtopic.php?p=307688#307688

    2. Jimboner says:

      learn to write better instructions faggot.

    3. Admin says:

      If you have any suggestions of what I have missed, please post that instead of just complaining.

    4. Ricky Helgesson says:

      Incredible work! I am proud to be Swedish. :)

      I will try to use this to find paths for vehicles in an offroad vehicle game. Will send you the results and contact you for commercial use.

      /Ricky

    5. Pingback: I still have to come up with a good title.. » Pathfinder

    6. Felipi says:

      left this in the home page, but got no feedback so i’m posting it here as well^^.

      sorry to post for this… but just wanted to say HOW AMUZED I AM WITH THIS!!! congratulations, it’s an amazing project. had never worked with AI or pathfind, and the actual game i’m working needs it and i could set everything up in just 2 hours thanks to your project! Totally noob friendly!

      When i grow up, and start selling games i will buy it!

      AH! btw, i’m working in a Tower defense game! And, right now my enemies move in a straight line, but soon i intend to upgrade my tower defense to let players make a maze with their towers, and so, i will need to scan the map everytime a player set up a tower in my grid. Is there any way to scan the map again every time i place a tower? Or the only options to scan the map is on startup or manually? Is there any way to call the function “scanmap” from another script?

      Sorry if it’s somewhere on this site, but i didn’t find it anywhere!

      Thanks!

    7. Admin says:

      Hi Felipi

      Sorry, I’m a bit lazy with answering these comments.

      I have posted an answer for you now though (where you first posted).

      -Aron

    8. Awesome system! It’s fast and working really well. One note is that the documentation for me was a little confusing. Perhaps a video tutorial that demonstrates all the aspects of it would be best for these types (frameworks) of things. Thank you for offering it for free to the community! That was really generous of you; I think this should be built into Unity. When I get a little better I try to post a video tutorial on how to use your A-Star system or as I’ve been calling it, “Aron-Star” (Maybe you should brand that!).

    9. Mani says:

      I’m working on a pathfinding/ Artificial Intelligence resources. Will make sure to add this.

      M

    10. Pingback: [Unity3D] A* Pathfinding project - Uititled

    11. Adam Waters says:

      Hey Aron,
      I’m trying to bring your path finding scripts into my project, but I can’t get past this error:
      The type or namespace name `AstarData’ could not be found. Are you missing a using directive or an assembly reference? (CS0246) (Warlord)

    12. Richard says:

      Hey Aron,

      Great system, integrated it very easily into our application.
      We have run into a snag though, we need to move the A* grid procedurally. The relative positions of the nodes do not change, but the entire scene translates and rotates in the world space.
      Is there anything that would allow us to do this in the code already? If not, where would you recommend we start?

      Thanks!

    13. Admin says:

      There is no built in functions to do that unfortunately, you can however change the positions of the nodes by script.
      There is an array of twoD arrays in the AstarPath script called staticNodes it holds the instances of every node for every grid ( staticNodes[gridIndex][xIndex,zIndex] )
      You can iterate it and modify the positions of the node.
      staticNodes[0][12,43].vectorPos = new Vector3 (1,2,3);
      The formula for the default position of the nodes is (C#):
      node.vectorPos = new Vector3 ( ( (float)x+0.5F) * grid.nodeSize + grid.offset.x , grid.offset.y , ((float)z+0.5F) * grid.nodeSize + grid.offset.z );

      The only problem is when you rotate the grid you cannot use the fast function for determining the closest node to the player and you will have to use the very slow function (it is used for non-gridlike navmeshes).
      You will have to change some code to do that:
      In all ToLocal functions in the AstarPath script there should be some code like this:
      if (active.gridGenerator == GridGenerator.Bounds || active.gridGenerator == GridGenerator.List || active.gridGenerator == GridGenerator.Procedural) {
      return ToLocalTest (pos,forceNodesUnder);
      }

      Comment out the if in those functions to make it look like this:
      //if (active.gridGenerator == GridGenerator.Bounds || active.gridGenerator == GridGenerator.List || active.gridGenerator == GridGenerator.Procedural) {
      return ToLocalTest (pos,forceNodesUnder);
      //}

      This will force it to use the slow nearest point function.
      The first one is on line 599.

      Hope it helps,
      Aron

      Sorry for answering late, I have been (and am) on holiday, but I’m home for one day so I will try to answer as many comments as possible.

    14. Admin says:

      Hi Adam

      I have been (and am) on vacation so I haven’t been able to answer your comment until now.
      You can fix the problem by including the AstarData.cs script from the GridData folder in the example project (2.8beta) (I should have put it in the /pathfinding folder, but well, that’s why you have betas) and the AstarDataEditor.cs script from the Editor folder.

      The AstarData.asset asset isn’t needed for the project to work.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>