Search Unity

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

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

  1. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64
    Sorry to bother you again, I think I found a bug, but it is not very important.

    When I try to exit through the rightest part of the map, the function IsTheClosestNodeWalkable crashes with an IndexOutOfBounds exception. I changed this to fix it:

    Code (csharp):
    1.  
    2. Node n = Map[x, z];
    3. return n.walkable;
    4.  
    Code (csharp):
    1.  
    2. if(x >= Map.GetUpperBound(0) || z >= Map.GetUpperBound(1)){
    3.     UnityEngine.Debug.LogWarning("Index out of bounds trying to get closest walkable node");
    4.     return false;
    5. }else{
    6.     Node n = Map[x, z];
    7.     return n.walkable;
    8. }
    9.  
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Thanks i look into it. The code was written rather fast for that part so.... :D
     
  3. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,155
    how can i move waypoints? i move parent waypointfinder object but moves colliders. position of waypoints is different than waypoint game object transform position. how can i move all of my waypoints?
     
  4. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You cannot move them all at once sadly.
     
  5. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,155
    why do you use different position field? why don't you use game object transform/position field?

    i added few lines of code to use gameobject position. now i can move them but i will test if it works fine :)
     
    Last edited: Dec 23, 2013
  6. Lucas-mv

    Lucas-mv

    Joined:
    Nov 17, 2013
    Posts:
    8
    Hi BFGames, I purchased your asset and I'm loving it so far. Outstanding performance and pretty easy to set up, even for a newbie like me.

    Is it possible to have a different "Climb limit" for certain objects? Or better, for certain tags? I'm not sure how hard it would be to implement it, but it would open a wide array of possibilities, like having spiders climbing through walls, while having other creatures not able to do so.

    Thanks in advance!
     
  7. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It would be possible, but it is not implemented at the moment, and would take some time to change.
    However ill write it down as i have a whole list of changes for the new year.
     
  8. Lucas-mv

    Lucas-mv

    Joined:
    Nov 17, 2013
    Posts:
    8
    That would be amazing. Thanks a lot!
     
  9. XenoAisam

    XenoAisam

    Joined:
    Sep 11, 2012
    Posts:
    7
    Just to inform, Terrain Collider make the waypoint system having a lag spike. I've known the issues from unity crash log. Possible due to my small terrain. To solve is just disable the collider
     
  10. Dragick

    Dragick

    Joined:
    Jan 4, 2014
    Posts:
    3
    How do I ask a pathfinding class how many steps it has in it's queue?
    I told the class where I want it to go then checked Pathfinding.Path.Count, it is at 0.

    How can I pass in a destination and immediately get a count of how many steps it has to take to get there?
    This is using PathType of GridBased .
     
  11. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The path is not always returned in the same frame as it Queues the path's to make sure it won't lag up your computer.
    So you cannot just call FindPath() and then use Path.Count right after. You need to use Path.Count where the path is returned.

    You find the return method for the path in: Pathfinding.cs, line 57. It is called protected virtual void SetList(List<Vector3> path). Inside that you can call count on the list.

    And there is no instant way to know. Because it will have to find the path using the A* algorithm no matter what.
     
  12. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64
    Hello again,
    I am having a weird problem.

    I am using a terrain as my stage and invisible colliders to further restrict the walkable areas. My problem is that in Unity, everything works ok but once I build for Android, iOS or windows, the generated grid differs from the one in Unity. For example, in a certain place I have a ladder, it has no collider, the player and monsters just walk on the terrain under it (the ladder is almost horizontal, just to indicate a difference in height in the terrain). In Unity I can see the generated grid and walk with no problems but after building the game I cannot walk by the center or the left part, I must stick to the right, as if the center and left cells were not created correctly.

    Any ideas about it? Maybe because of terrain LOD?

    I have thought of hacking a little into Simply A* and adding a new property to the Pathfinder prefab, when checked, it would create a new Gameobject and store the grid info into it so I can save it as a prefab. Then add another property, assign this prefab and make it so if the prefab is found and the info is correct, Simply A* loads the grid info from this prefab instead of generating it.

    Do you see any potential problem if I do this?

    Thanks!
     
  13. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Don't know why its not working when you build, and really hard to say. Have worked fine when i tested on my android phone (Nexus 4).

    For the other part it is possible but not that straight forward. You need to serialize the info so it can be saved. Store it in an XML file would maybe be a better approach, but as said its not that straight forward.
     
  14. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    I'm looking at picking this up for a voxel game I'm working on. Does this work well with an infinite voxel world (ala Minecraft)? How about with the terrain being changed regularly (due to player/AI modifying the terrain). I'm concerned about performance due to the grid being changed often. Please give any insight, thanks!
     
  15. -JohnMore-

    -JohnMore-

    Joined:
    Jun 16, 2013
    Posts:
    64
    It working great!
    I took your function CreateMap and if in SavingDirection I save the serialized map to a text asset, then assign the asset to pathfinder as SavedMap. If pathfinder finds a SavedMap when starting it skips the Fill up Map section and just loads it from the asset. I have tested it in Windows and Shield and it is working great in both.

    By the way, I didn't need even an hour, you code is well organized and easily readable so thanks for that too :).
     
  16. zenforhire

    zenforhire

    Joined:
    Nov 5, 2012
    Posts:
    65
    Hi All,

    Will the product work for a 2d hex grid board? Not an auto generated square grid.
    The board will be 3ooo hexes. I will not manually connect these.
    Is there a FindNeighbors method I will override?
    Searched this thread but could not find the answer.

    thanks
     
  17. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It is not set up for hex-grids sorry :)
     
  18. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    I need to be able to traverse a graph of 32,000 nodes with each one having connectors to one or more other nodes. In some instances, if a parent node is "secured", the paths going away from it to other nodes will be blocked. It can only be circumvented if there are others routes to the nodes.

    Would it be possible to traverse the graph considering some paths may be invalid? My specific problem is a universe of thousands of galaxies, systems, and planets. Some planets will not be accessible by other planets unless they have a path between them. And, even if there is a path, if a path leads to a planet that is owned by an enemy, paths from the enemy planet will not be usable. You may be able to connect to planets the enemy planet connects to, but not by going through the enemy planet node. Make sense?

    Also, this needs to work server side as well. Can I use the code in any c# environment or does it require Unity?

    Thanks!
     
    Last edited: Jan 24, 2014
  19. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Well your case is pretty specific, and the problem with my waypoint system is:

    1. It is for smaller systems, as you set nodes by hand. Setting up 32.000 nodes by hand? Well good luck hehe :)
    2. It is build to work in Unity, using a few unity methods you cannot use server side.

    However i can guide you a bit. When you use an A* algorithm you do no traverse the graph as such but expands it based on fitness until you reach your target, and then you traverse the path. So instead of checking the validity of each path after running the algorithm and then traverse till the problem and run it again from there on, you should update the nodes dynamically. In this matter you will effectively always find the correct path based on a single search.

    However for your game i do not think you will find anything on the asset store that fit your needs, so you probably need to write the code for it yourself. If you know what your doing and know how to write a proper A* implementation it should not take that long. And the basic idea behind the system will work in the same way on a server, but that all depend on your setup in Unity, and i have no idea of how you done it so cannot help there.

    Hoped it gave you an idea of how to go on with it.
     
  20. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    This system is quite perfect for what I need. However, I seem to be having one issue. I have a testing grid of 10x10 quad objects that the player and AI character can move around on.

    I want it to be that characters can move only in vertical or horizontal directions, not diagonals. So my first square is positioned at 0,0 (such that 0,0 is right in the middle of the square). The top-right one is at 9,9. This is on an XY grid.

    The thing is, when I go to move from, say, 1,1 to 4,2, I get these coordinates filling up the list of vectors to move to:

    1,1 -> 2.5, 1.5 -> 3.5, 1.5 -> 4.5, 1.5 -> 4, 2.

    This is not what I want. When it moves to those decimal numbers it goes on the edges of the squares and that doesn't look good.

    Is there any way I can make them be centered as whole numbers to where it will work correctly? I do have "move diagonally" turned off.

    Thanks in advance.

    Edit: figured it out. Turns out the issue was:

    Code (csharp):
    1. float x = startX + (j * Tilesize) + (Tilesize / 2); //Position from where we raycast - X
    2. float y = startY + (i * Tilesize) + (Tilesize / 2); //Position from where we raycast - Z
    I didn't want that Tilesize / 2 at the end there.
     
    Last edited: Feb 5, 2014
  21. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Good you figured it out.
    However it could be fixed by setting the maps start position corretly.
    So if you want it in the middle of 1,1 you need to start the map at 0,5 with a tilesize of 1 for example :)
     
  22. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Ah. That was a case of me simply not understanding how the system works well enough, then. I'm fairly new to programming and learning :).
     
  23. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    This has been working great for me so far. But now I am trying to address the issue of updating the map dynamically. I see that the system updates on a certain time interval. Is there any way to make it update when I want to? Say, calling some UpdateMap() kind of function. Because for the most part my tile grid is going to be not changing too much. But I want it to update whenever a player finishes moving so that the system knows not to let other players travel through each other. I also want it to update whenever some events happen that dynamically change the map every so often. But I don't want to waste resources updating constantly when I don't need to.

    And would I put a separate dynamic update script on each player? Or would I use just one and run an update map function on it? I'm a little confused about how that works!
     
    Last edited: Feb 13, 2014
  24. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    In the DynamicMapUpdate.cs file, you can make this method public instead of private: private void UpdateMapOnce()
    Now just call this method from where-ever you need to.
     
  25. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    I'd like to use this asset to control physics driven (rigidbody) AI characters, I would need to use the waypoint system because I have multiple floors/levels. I have a few questions if you don't mind:

    1) I noticed the example scenes use character controllers, would this asset also work for a rigibody and capsule collider setup? Eg. using AddForce for the movement
    2) I would need my AI characters to also search for vertical paths (climbing) when pathfinding, I assume this is possible?
    3) If I would want to add some simple dynamic object interaction/avoidance I'm wondering whether it would disrupt the pathfinding functionality. Eg. If I shoot a raycast in front of the AI character, and when that raycast hits a "jumpable" object I would add a force on the y axis to get the character to jump over this object while continuing to pathfind its way to the target. Similarly if I add a force on the negative or positive x axis to have the AI character try to move around the object to its left or right while it is pathfinding to its target. I'm wondering would such functionality disrupt the pathfinding since it would move the AI character slightly of course, would this confuse the AI character as to which waypoint it should go to next?

    Your thoughts please.
     
    Last edited: Feb 18, 2014
  26. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    All is doable with a bit of work. What Simply A* does is simply return a list of positions a character can follow, how you follow them is up to you. All movement scripts are only examples, and it can be done a 1000 other ways.

    Often i use distance to know if i am close enough to a position to start moving towards the next one. Now with AddForce at a high velocity this might be difficult, sames goes for obstacle avoidance. What ive done before my self to fix things like this use a Timer and check if i am closer to the "next" node position than the one i am searching for, and then make this the new target node. So you can do it, but you will need to play around with it a bit until you get it right ;)
     
  27. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ok sure that sounds good. I was going to wait for your updated "Pro" version but on the WIP page you mentioned that it's on hold, so I think I'll stick with this.
     
  28. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    I have another question if I may about the disallowed tag objects for the waypoint system. In the video you mention that when an object with disallowed tags is blocking the path you can pick whether the "closest waypoint" or the "exact position" is used as the pathfinding target. I don't quite get how this works. For example how does the agent know which "closest" waypoint to pick since it too may be blocked by the tagged object.
     
  29. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Closest and exact waypoint has nothing to do with tags. It means that if it is closest the first node will be the one closest to your position and the last will be the node closest to your destination. If you use exact then the first node will be your position and the last node will be your exact destination point.
     
  30. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Oh ok, I totally misunderstood then. What do the disallowed tags do then?
     
  31. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    They are for the grid based solution only, where the decide what tiles should be walkable and not.
     
  32. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ah I see, I was hoping to have that functionality with the waypoint system :(

    Is there a way to be able to use the grid system along with the waypoint system or do they only work on their own? For example if I used the grid system on each floor of a building and then used waypoints to get from one floor to another, could this work?
     
  33. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    They can both be in a scene, but can not be connected.
     
  34. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hmm that's a bummer. I guess I'll have to wait for the Pro version then since I definitely need both multi level pathfinding and dynamic objects. Any ideas when you will be continuing development of the Pro version?
     
  35. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    I am working full time on a PC Title at the moment so not in the next couple of months.
     
  36. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    That's fair enough, thanks for being honest. I have a few more questions if you don't mind. Firstly is it possible to have multiple grids and waypoint systems in the same level i.e. have multiple Pathfinder and WaypointPathfinder prefabs in the one scene? Because I'm looking at the documentation file and I've noticed there's no variable for adjusting the Y axis position of the grid. Say if I had a building with 3 floors and I wanted a grid to affect only the 3rd floor with the waypoint system affecting all the floors underneath, could I position the Pathfinder prefab to the 3rd floor's height and have it only affect the one floor? Lastly, in the grid demo scene there are several multi-level platforms stacked on top of each other and connected by ramps; is there a limit to the height that these objects can be placed on top of each other or how does the grid handle the height differences between these objects?
     
  37. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You can only have one of each in a scene (Pathfinder Waypoint systems).

    For the grid it simply takes the first valid object it hits from above looking down and uses that for deciding the position of the grid node and if it is walkable or not. In the grid inspector you can set your max and min Y values. It will only look for items in between these values.
     
  38. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Ah ok, I suppose using the waypoint system I could set up different areas of waypoints and simply not have them connected to each other eg. in your waypoint demo scene one could disconnect the waypoints connecting the floors together creating separate "groups" of waypoints per floor. This way I would still be using only one WaypointFinder but be able to have the functionality for multiple independent waypoint systems, if that makes sense.
     
  39. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You could do that, just be careful in the way you search for it (some distance check would be a good idea).
     
  40. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Hi,
    just baught this great plugin.
    However i got some Exception trying to make navigation grid on a super simple level :

    OverflowException: Number overflow.
    Pathfinder.CreateMap () (at Assets/Pathfinding/Scripts/Pathfinder.cs:117)
    Pathfinder.Start () (at Assets/Pathfinding/Scripts/Pathfinder.cs:60)

    And the level i made is super simple, the onmy problem is that grid don't generate ? i followed PDF tutorial.

    Could someone explain me how to have generation grid to work please ?
    http://s24.postimg.org/4hz1p8u91/pathfinding.jpg
     

    Attached Files:

    Last edited: Feb 26, 2014
  41. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Well you set it up almost perfectly, BUT. You need to set map start position in the lower left corner (lowest x and z) and end position in the upper right corner (highest x and highest z) ;)

    If you still got problems after that feel free to mail or PM me, cheers :)
     
  42. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    Yes, that what i find out and had it work :)
    Perhaps it should be put more clearly in the PDF docs about left bottom and right upper corners ? I seen the picture but did'nt thaught we had to follow exactly that corners.
    I don't know if it would be possible to have some visual Gizmo to capture X,Y corners from some top down camera ?

    Thanks again for that great quality and easy ot use package.
     
  43. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Im glad that it is working. And the doc's is a bit old, think i will make an updated version next week. :)
     
  44. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    For the error i had with PathFinder even if we don't have some visual helper to capture corners, why not putting some simple Message box warning saying :
    "Navigation Grid can't generate : Start point must be left bottom corner and end point must be Top upper corner"
    For example ?

    Cool for the doc :)
     
  45. superbneo11

    superbneo11

    Joined:
    Feb 27, 2014
    Posts:
    1
    I’m working on a TD game and want to use a pathfinding system. I found out that your Simply A* can help my work.
    So I want to ask you some questions for this plug-in before purchasing it. First, does Simply A* support NEW Unity4.3.4 2D system which the map is created on XY-Plane?
    Second, does it support dynamic pathfinding in runtime so that my characters can find new paths automatically in real time when player place new towers.
     
  46. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    1. No sadly it does not support the new 2D system (see asset store description). :(
    2. It can handle dynamic runtime changes, but as it does not work for the 2D system i guess that does not matter. :)
     
  47. CS-Kyle

    CS-Kyle

    Joined:
    Dec 12, 2013
    Posts:
    3
    Hey, just looking at buying a good pathfinding solution, and yours seems like it might be a viable option.

    In the first post, there's a video showing dynamic grid map updating "coming soon", but that edit was a while ago - what's the news on that feature?

    Basically, I have a very simple setup (the nav map is just a flat plane, essentially), but there are several dynamic objects moving around constantly. The only purpose of the pathfinding system in my game is to have those dynamic objects avoid each other. Is that doable at the moment, or is the dynamic grid updating still in progress?
     
  48. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The dynamic updates to the map works, however it is made to update the map when items a set into the game or removed mainly. It might be too performance heavy if you need to update a large amount of objects each frame, specially if it is larger objects.
     
  49. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    Hi,

    i would have just some question, where a much more expensive pathfinding provider failed:

    - How does it act on unity terrain (non plain), are there strange behaviors?
    - Does the unity terrain trees stop the agents, can the agents avoid these trees? (not so important)
    - An RTS game has usually a lot of agents. Are there any sick behavior, if moving 100 agents at the same time (with multiselection, on non plain unity terrain)?
    Map: 1000x1000, A* Grid 500x500x2, 100 agents, send them about 700 unity-units far away
    - Are the units movement (about 100 units) on a non flat unity terrain stable, that means no slalom on a free and even path, no dancing (moving forward, backward, sideways)?
     
    Last edited: Mar 15, 2014
  50. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    1. The few tests i did on the Unity terrain worked fine, also for non plain terrains (caves and such is a no go though).
    2. Colliders is used to determine if a tile is free, so if the tress got colliders set up right, you can avoid them.
    3. Well pathfinding for RTS are kinda special because of the amounts of units that will move. There are different ways to handle this but it is not a part of this package as it is extremely game specific. I would not recommend running pathfinding for each unit no matter what A* asset/package you are running, as the algorithm is what it is.
    4. Why is the grid 500x500x2, the 2 makes no sense in a 2D grid.
    5. There is no steering behaviours in this package, it is as the name says, simply A* with some neat ways to handle the map (grid). Everything else you need to add yourself.