Search Unity

[Released] BFGames: Simply A* Pathfinding! NOW FREE

Discussion in 'Assets and Asset Store' started by BFGames, Dec 28, 2012.

  1. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    I have a situation here. SimplyA* for what I understand calculates the pathfind in parallel. I want to make a function to give params and return a path list. What I`m doing now is start the calculation inside a IEnumerator and wait for a 2 frame delay using WaitForEndOfFrame 2 times).

    These 2 frames are suficient to have the result inside a Path variable on this object. I`m using Waypoint Based Path Type. Can this be done? Where do I need to start looking?

    Thank you!
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Not sure what you mean about these parameters... Is it a separate list or a part of each path node?

    I return the path for the waypoint system in WaypointPathfinder.cs line 76 via the FindPath method which returns the path as a list of Vector3's. You can change the return type in FindPath to whatever you like, just remember to change your arguments taken in the callback function too then.
     
  3. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    There is never gonna be a pro version. I started on it long time ago but due to time needed for actual game projects i had to drop it. Anyways Apex Pathfinding on the asset store does more or less what i did in my system and intended to do so take a look at that (for grid based systems).
     
  4. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    I just want to pass start and endpoint and have a List of nodes. What I noticed is that using the method "FindPath" from the "Pathfinding" class (the actual base class for my moving objects), I have a void return:

    Code (csharp):
    1. public void FindPath(Vector3 startPosition, Vector3 endPosition) {}
    So when I call FindPath, I wait for 2 frames and check the Path variable (that is assigned elsewhere via FindPath) and see the results.

    What you saying is that what I did above is not necessary? Can I use WaypointPathfinder.FindPath directly and independently to check a node path between 2 points?
     
  5. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You can use it directly as it is a singleton.

    Code (csharp):
    1.  
    2. WaypointPathfinder.Instance.FindPath();
    3.  
     
  6. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Awesome. I will have to remake most part of the project :p
     
  7. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    I have a strange situation. I'm using waypoint pathfind (exact position). And sometimes the object goes to the target in a straight line, ignoring the path. Do you have *any* idea why this could be happening?

    The Scenario:
    The object goes from point [start] to [target A] and waits for 3 seconds and back to [start]. But when the object is waiting I can send it to another location. I'm using coroutines to queue the "back" move.. and when I command it to go somewhere while the object is waiting, i cancel the coroutine and send another path to the object from [target A] (actual position) to [target B].

    Thats the exact moment when this behaviour happens. It goes from [target A] to [start] in a straight line, then from [start] to [target B]. The problem is, this is pretty random. If you have any clue on why the object might ignore the path I appreciate
     
  8. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Kinda need some code. The pathfinder always just returns the positions of the waypoints, so it must be some flaw in the movement code or some path lists not being cleaned.
     
  9. jammyt

    jammyt

    Joined:
    Jul 7, 2014
    Posts:
    12
    Hi,

    Firstly thanks for system, I've just started playing around with it and it's really useful.

    I'm using the waypoint system at the minute, using it in 2d and its working fine.

    One thing which I found strange though was that it's difficult to tweak the position of waypoints.

    Is there any reason the waypoints have their own position as opposed to using the transform position? I've changed the scripts here to use the transform.position and then all the usual Unity moving node functionally works in the editor making it much easier to use.

    Just wondering why its not like this already or am I doing something stupid which I don't know about as I only downloaded it this evening?

    (I also had problems adding nodes in a 2d environment but I've added a 'background' cube for now to get the add waypoint clicks to work)
     
  10. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The system was made way before 2D in unity existed! Thats why its not set up that well for the 2D system. :)

    It was to handle objects differently, however its fine that you use the transform. Should work just fine. You can also use ExecuteInEditor if you want it to update the gizmos. I was not as good a Unity programmer when i made the system 2 years ago hehe.
     
  11. borzale

    borzale

    Joined:
    May 17, 2013
    Posts:
    3
    Hey there.

    Thanks heaps for the pathfinding project, it's been great so far!

    I just found a frustrating error which you might be interested in. None of my paths were being returned despite setting up my project the same as the grid example. The problem was, "Max Falldown Height" and "Climb Limit" being set as 0 (as I have a flat map, I don't want any climbing). In the documentation it says to leave these as 0, but setting it to 0.1 fixed the problem. I assume any positive number will likely fix this, no matter how small.

    Any idea why this is? Let me know if you want any more details.
     
  12. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Well it depends on your level really. If its a flat plane 0.0f should work (did for me at least). If it is not a flat plane then ofcause it won't be able to climb or fall down where needed. Might be a bit misleading in the PDF, i will change that.
     
  13. Harmonickey

    Harmonickey

    Joined:
    Feb 13, 2015
    Posts:
    1
    Is there a DynamicMapUpdate available for PathFinder2D? I have a 2D game that uses only that pathfinder, but the DynamicMapUpdate.cs file uses only the PathFinder object. The PathFinder2D object does not have a DyanamicMapUpdate method.
     
  14. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Nope, sorry! Never got around to do that, and as i really don't work on the project anymore it won't be added. But if you know a bit about coding it should be really easy to implement if you base it on the one used for the 3D tilemap.
     
  15. SimonAlkemade

    SimonAlkemade

    Joined:
    Feb 4, 2009
    Posts:
    432
    Hi, I'm using Simply A* and it works great. But now I tried to compile it for iOS and then it crashes. I'm working in unity 4.6.2 free and Xcode 5.

    It could also be an Xcode thing, I tried to clean but that doesn't help much.

    dyld`dyld_fatal_error:

    0x2feec0c4: trap

    0x2feec0c8: nop

    Any suggestions?
     
  16. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Hey Simon. Never had that error or heard of it before so might very well be an Xcode thing.

    Edit: Just did a google search and it is indeed an XCode thing. As i am not a MAC user i cannot really test it out and help you sorry.
     
  17. northman

    northman

    Joined:
    Feb 28, 2008
    Posts:
    144
    Hello,
    Is it any easy way to avoid mover go through each other on the path and do not effect on performance?
    I mean example, the A.I. tank move on path not go through other tank's body.
    Thanks,

    S.Z.
     
  18. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Nope, this is up to the user to code, as its not a part of the actual path planning (hence the name simply A*). You can user simple steering behaviors for this :)
     
  19. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    My system is not really made for 2D either...
     
  20. lkarus

    lkarus

    Joined:
    Feb 25, 2015
    Posts:
    51
    Hey BFGames, first of all thanks for the awesome pathfinding asset.

    I've gotten the plane to draw out the grids for me, but I'm having trouble getting objects to be disallowed. I procedurally place walls on the wall, so I instantiate prefabs of walls onto the map. So this is what I have done:
    1. The wall prefab has a 'Wall' tag and is also in the disallowed tag.
    2. The wall prefab has a SetGrid script attached to it (I played around with the X and Y values and they dont seem to be affected by it, so the X and Y values are random values).
    3. The wall prefab either has a box or a mesh collider.

    But for some reason, when I instantiate the prefab, the area where the wall is not empty space like the sample scene included. I was hoping to get some help regarding this issue. Thank you in advance!

    Edit: I tried creating a huge plane that is way bigger than my map. I found out that the map is covered with green color, but the rest of the are not red. They are just empty(transparent)
     
    Last edited: Apr 2, 2015
  21. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Asset Store Woking.
    This is exactly what I wanted. It works like a charm.
    I want to ask that is is possible to get the distance of target and object not the vector 3 in this thanks for this asset
     
  22. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Hey Teekay. If you are working with procedural levels, then you need to create the level before the map is generated, which can be done in Unity's Awake() method. If you are creating walls through out the game after the Start() method has run then you can use update the map (see documentation pdf)
     
  23. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Unity can give you the distance between two objects using Vector3.Distance().
     
  24. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    sorry again I should have said the length of path between target and object. Vector 3 would just give me the distance not path that wont be good in zig zag paths :(
     
  25. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It returns a list of vector3's so just iterate through the list and add all distances then.
     
  26. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    thanks and this asset is awesome and it's free this is the best free asset on asset store for grid based pathfinding. thanks for help and this asset :)
     
  27. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Hello,

    In my game I have a ship constantly moving on water meaning its x, y, z position and rotation are always in flux.

    I would like to have the ai crew be able to move about the ship while it's moving.

    I am wondering if your pathfinding solution is able to accomplish this? I assume it means modifying path finding at runtime in a reasonable way but any waypoint pathfinders that I have looked at so far don't seem to be capable of that.

    Any help would be much appreciated, thanks!
     
  28. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    No its no able to do so. And normally you will use a local based system for this. So you have a local pathfinding system that translates into the correct position based on the ships local coordinate system. Then all crew members will be a child of the ship and move accordingly to the ships local coordinates.

    Don't think you will find any system for this on the asset store. Probably need to write it yourself :)
     
  29. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Dang, okay I'll have to look into writing my own system I guess. Thanks!
     
  30. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
  31. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It will if you know how to use a for loop and simple float addition, which is basic programming...
     
  32. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    ok sorry for noob questions but it is giving me a message 'Empty Openlist, closed list' I have a rigid body and pathfinding script and a script to get component of pathfinding and it sets the target to a static vector3 setup at awake.... can u please help
     
  33. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    Edit- In grid based path finding
     
  34. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    1. The map is created in Start() which runs after awake.

    2. When it gives Empty Openlist, closed list, it means that it could not find a valid path. Make sure your map does not have empty closed areas or you don't stand on a unwalkable tile from the get go. You can visualize the map so take a look at that.
     
  35. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    OK thanks the problem was that my object was in air not on the ground :)
     
  36. Toko1111

    Toko1111

    Joined:
    Jun 13, 2015
    Posts:
    2
    Hello,

    thank you for your free script !
    I just have a little problem. I can't figure out how to make my pathfinding dynamic (yes I read the tutorial). I just don't know on which game object I have to put the Update Map script. If I put it on the Pathfinder it says that I need a renderer and if I put it on the ground it throws me an error that says :

    NullReferenceException: Object reference not set to an instance of an object
    Pathfinder.FindClosestNode (Vector3 pos) (at Assets/Pathfinding/Scripts/Pathfinder.cs:351)
    Pathfinder.DynamicRaycastUpdate (Bounds b) (at Assets/Pathfinding/Scripts/Pathfinder.cs:842)
    DynamicMapUpdate.UpdateMapOnce () (at Assets/Pathfinding/Scripts/DynamicMapUpdate.cs:37)
    DynamicMapUpdate.Start () (at Assets/Pathfinding/Scripts/DynamicMapUpdate.cs:15)


    Thank you for your help, have a nice day
     
  37. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Needs to be on the actual objects that are going to be used for updating the map.
     
  38. Toko1111

    Toko1111

    Joined:
    Jun 13, 2015
    Posts:
    2
    Oh thank you very much :) I am kind of new and couldn't figure this out ! Thank you a lot
     
  39. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    142
    Hi
    Nice work with the Pathfinder I really like it.
    Just a question...I am trying to make duplicated instances of a cube with a waypoint on it but the node seems to not retain the positioning info. i added position = transform,position to the WaypointNode.cs Start function but they only show up on Play.
    At the top of the node info in the inspector it says " multiple instances not supported " (or something like that).
    Is there a way to allow duplications that can be seen in the editor?
    thanks
     
  40. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    142
    Also , is there a way to get the nodes to be constantly visible in the editor? It is a bit tiresome constantly having to select them all in order to see where they are
     
  41. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Its like 1½ year ago that i played around with that part, so cannot really remember whats possible, sorry.
    And as i don't work on the system anymore it is up to people to add stuff like that them self. Thats why all code are available :)

    Hope you find a solution.
     
  42. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    I have a game where I have a complex and very large 3D terrain like a forest, has trees, rocks, hills, mountains, cliff, water etc. Then I have animals, players, and other things roaming around.

    Some objects are moving following a path, but other objects also moving can easily block the way of each other. Maybe they can easily fall off a cliff, but the have to find a way to get back on the path, by themselves using AI, without getting stuck somewhere.

    I don't want to waste weeks trying out this path finding package just to find out its too slow, or uses too much memory, or it cant work in this case etc.

    Does anybody know if this path finding package would be good for my application?

    Thanks
     
  43. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello again,

    This package seems to use and generate a grid. How does it store this grid, does it keep it in memory all the time? does it generate it over and over? what if I have a really large 3D terrain, like a forest, will it take a long time and lots of memey to generate a grid for that? does it create the grid at run time, or while I'm in the unity editor, then save a big grid to be carried along with the game package ?

    Thanks
     
  44. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It will not take too long, but it is stored in memory and not optimal for mobile if you have larger levels. It can only create the grids in play-mode, not in the editor.

    Also there is a maximum size of 1000x1000 for the grid at the moment, so its not really build for large open worlds.
     
  45. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Hello again!

    I'm still having some issues with pathfinding. Please take a look at the image below. The blue squares are the real nodes and the white spheres are actualy the path calculated (a list of Vector3). The path itself is ok, but I need to know if some node are blocked. What I'm doing today is comparing calculated path and nodes positions and try to guess what node belongs to what position. Note that before the end node (the bottom) there is no blue square (in fact, it all started wrong from top) and I can't find a node and I cant reach that object.

    This problem happens *only* on standalone. Inside Unity Editor all works good. Imagine the size of my problem. That being said, I have a few questions:

    1) Can I have a list of nodes returned from WaypointPathfinder.Instance.FindPath() ?

    2) If not, what could be the cause of this happening only on standalone?

    3) Or, at least, Is it possible to have returned the exact position of the node (or at least very close) to math my comparisson (in bold above)?

    If relevant: I'm using ExactPosition SearchMethod. And here is my changed WaypointPathfinder.cs source code

    Standalone:


    UnityEditor:
     
    Last edited: Aug 4, 2015
  46. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    1) Sure you will have to re-write it though. But as it already takes the position from the node, you could simply add the node to a node list instead of a vector3 list and return that. Will require a bit refactoring though.

    3) Pretty sure that it actually uses the exact position of the waypoint, so don't know whats wrong there.

    In regard to the standalone thing, then thats very annoying. But remember that this project was created in 3.x and we are now on 5.x - so something might simply not work that well anymore.
     
  47. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    I managed to make it work changing the FindClosestNode function:

    Code (CSharp):
    1.     private WaypointListNode FindClosestNode(Vector3 pos)
    2.     {
    3.         var lowestDist = Mathf.Infinity;
    4.         WaypointNode closestNode = null;
    5.         for (var i = 0; i < Map.Length; i++)
    6.         {
    7.             var wp = Map[i];
    8.             var dist = Vector3.Distance(wp.position, pos);
    9.             if (dist >= lowestDist) continue;
    10.             lowestDist = dist;
    11.             closestNode = wp;
    12.         }
    13.         return closestNode != null ? new WaypointListNode(closestNode.position, closestNode.ID, null, closestNode.neighbors) : null;
    14.     }
     
  48. stevecus

    stevecus

    Joined:
    Jul 10, 2014
    Posts:
    3
    Hey,

    Does anybody know where in the code I edit so that if the path cannot be created, because it is blocked by a wall, it looks for the nearest wall segment and goes to knock it down? I clear the list and Findpath again when the buildmenu is closed, I also update the gridnavmesh.

    in Psuedo;

    Path to target is not valid.
    I've searched for the nearest tag and am now heading to it.
    Its destroyed, head for my original target/ find another wall if blocked.

    Code (CSharp):
    1.  //If we have no nodes on the open list AND we are not at the end, then we got stucked! return empty list then.
    2.                 if (sortedOpenList.Count == 0)
    3.                 {
    4.                     //Vector3 closestWall = FindClosestWall().transform.position;
    5.                     //SetStartAndEndNode(transform.position, closestWall);
    6.                     print("Empty Openlist, closedList");
    7.                     listMethod.Invoke(new List<Vector3>());
    8.                     return;
    9.                 }
    is it his section as it calls the debug/print comment when the end point is null and the list is returned as empty.

    Thanks,

    Steve.
     
  49. PhoenixRising1

    PhoenixRising1

    Joined:
    Sep 12, 2015
    Posts:
    488
    First of all I would like to thank you for this awesome asset, and once I get closer to having a project worth calling a game I will definitely purchase the pro version. Now I have a question.

    I just wanted to implement this asset on a plain ground but I'm having problems with the movement. I'm trying to make a cube move to the other one, but it tries to go halfway into the ground, you can see it in the 2nd pic (rigidbody has been added to the moving cube). In the last pic I disabled the rigidbody and you can clearly see that half of the cube is burried into the ground. I tried to find some kind of offset but no luck.






    What do I do wrong?
     
    Last edited: Sep 21, 2015
  50. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It is because it is moving to the cubes transform.position which is its center.