Search Unity

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

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

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Hi there,

    Haven't responded for a while as I've been working on other areas of the game. But now that I'm returning to this again, I notice that when the map is created upon start, this "Create2DMap" method is called to initialize the map.

    This way, you have the starting and ending positions and make the map based on that.

    But is there a way to dynamically update the map in a similar way? I was looking at the UpdateMapOnce() code and I see something about a last position. I'm not sure what that's supposed to represent.

    So I'm not sure exactly how to use this. Would I put one of that script on something such as a Game Manager, and just call it whenever I need to update the map dynamically?

    Or does the object calling it have to be in a specific position?

    Thanks in advance.
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The dynamic update map is for the 3D grid bassed solution.
     
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    So is there no way to dynamically update a 2D grid? Would I just call create 2D map again, or would that be too hard on performance?
     
  4. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Nope there is only one for the 3D grid (also says so in its description ;) ).
    It would not be a good idea to recreate it because of performance. If you still want to play around with it, then you need to do it in LateUpdate().
     
  5. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Well, yay, it says it in the description! That makes everything better!

    ...

    Looks like I'll be figuring it out myself.
     
  6. Kai_Zu

    Kai_Zu

    Joined:
    Dec 14, 2013
    Posts:
    17
    Hi.

    When compiling the scripts in MonoDevelop-Unity (ver. 4.0.1) I get the following error message (thrice) when doing a complete rebuild:

    c:\xxxxxx\Assets\Pathfinding\Editor\WaypointEditor.cs(5,5): Error CS0246: The type or namespace name 'WaypointNode' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Assembly-CSharp-Editor)

    And when I try to add a waypoint in the Editor (Unity Free, ver. 4.3.4f1) I get this error:

    NullReferenceException: Object reference not set to an instance of an object
    WaypointEditor.OnSceneGUI (UnityEditor.SceneView view) (at Assets/Pathfinding/Editor/WaypointEditor.cs:78)
    UnityEditor.SceneView.CallOnSceneGUIAfterGizmos () (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/SceneView/SceneView.cs:1664)
    UnityEditor.SceneView.OnGUI () (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/SceneView/SceneView.cs:960)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

    If it helps at all I've noticed that by default MonoDevelop-Unity chooses .NET-framework v3.5 which does not allow for default parameters. They're used in some of the node-related stuff. Thus I always need to change all the projects to v4.0.

    So far I've used the Grid-based pathfinding and it works fine but I need to use the waypoint-based pathfinding as well.
     
  7. thekill473

    thekill473

    Joined:
    Aug 26, 2012
    Posts:
    9
    For the waypoint system, how do I move a node once I've placed it other than manually typing in the values.
     
  8. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi BFGames,

    Sorry if it has been asked before. In Waypoint-based solution it's possible to add or remove a waypoint in runtime?
     
  9. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    Hi,

    Do you have local avoidance mechanism?
     
  10. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    In an RTS game are units with different sizes available. One can pass through between two obstacles and the another not. Is it supported in your asset?
     
  11. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Dont know how i missed your message sorry, but the answer is no, only the grid system is build to change at runtime.
     
  12. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    No you will need to add this yourself. Its not build with specific genres in mind. (and there is no local avoidance either)
     
  13. EasyPlay

    EasyPlay

    Joined:
    Mar 23, 2014
    Posts:
    8
    I look for many findpathing solution for my problem.My problem is following:
    1,my Gid is not Irregular polygon,it made by points;
    2,my Gid is dynamic created every time;
    the following pic show:
    1,first pic2.png
    2,change to :
    pic.png
    I want to the red or green point move in the polygon ,the nails are

    obstacles,I slice the polygons to smaller.

    Can your solution solve my problem?
     
  14. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi! I am looking for easy to setup pathfinding solution and I was wondering will this package work for a situation where you need to find a path on the cube (think like rubiks cube)? This would be grid setup or something else?

    Thanks!
     
  15. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    As i answered on mail then it wont work for the rubricks cube case no.
     
  16. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Announcement:

    Hello every one! As i lack time for supporting and improving the project, it will become FREE from the 15th of September!

    Enjoy.
     
  17. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    F*** it, just submitted it! Will be free as soon as it is accepted!
     
    hippocoder likes this.
  18. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It is now free, removed the old 2D support though.
     
  19. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Hello,
    I bought you your Asset in July for $20, and I have sometimes a exception with more than 300 units, I tried to understand why, but for moment I did't find.

    IndexOutOfRangeException: Array index is out of range.
    Pathfinder.FindEndNode (Vector3 pos) (at Assets/Pathfinding/Scripts/Pathfinder.cs:398)
    Pathfinder.FindPath (Vector3 startPos, Vector3 endPos, System.Action`1 listMethod) (at Assets/Pathfinding/Scripts/Pathfinder.cs:243)
    Pathfinder+<SinglePath>c__IteratorC.MoveNext () (at Assets/Pathfinding/Scripts/Pathfinder.cs:226)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    <PathHandler>c__IteratorB:MoveNext() (at Assets/Pathfinding/Scripts/Pathfinder.cs:221)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    Pathfinder:Update() (at Assets/Pathfinding/Scripts/Pathfinder.cs:97)
     
  20. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Hello menfou!

    I would like to help, but your line number errors do not add-up with the newest version that i have? Did you change anything in Pathfinder.cs?
     
  21. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I sent you a example project by email.
    I made some modification for Mobile.
     
  22. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Im playing with the Waypoint solution, and how can I set a node unwalkable, but still be able to calculate an alternative path? The CheckEndPosition function check for a tag to avoid.

    What I need is when I calculate the path, it checks each waypoint node tag (or script variable, or anything) for a blocked node. If a blocked node is found, cancel this calculation and try another route.

    Any ideas?

    EDIT: Solved!

    If anyone interested, look for the following code inside WaypointPathfinder.cs:

    Code (csharp):
    1. if (wp != null)
    And change it to

    Code (csharp):
    1. if (wp != null && !wp.IsObstacle)
    I added a boolean inside WaypointNode.cs.
     
    Last edited: Sep 8, 2014
  23. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Hey guys im on vacation at the moment so answers will be far in between.

    For vincent, thats a fine solution. It would also be possible to ADD weights to the waypoints such that is more likely to take some routes than others.
     
  24. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    130
    Having weights still enable walks. What I want is a not passable point. If there is no options, the player needs to remove this "blockable" node to open path again.
     
  25. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Hi there, great asset!

    I just have one question regarding the tower defence scene. When I tried to mimic the behaviour for towers that will block the path, I keep getting an array index is out of range on this line

    Code (CSharp):
    1. Node n = Map[x, z];
    in the FindClosestNode function.

    Here is the code I use upon placing a tower:

    Code (CSharp):
    1. Pathfinder.Instance.InsertInQueue( _StartPosition.position, _EndPosition.position, CheckPath );
    _Obj is the tower that has just been placed.
    Code (CSharp):
    1.     void CheckPath( List<Vector3> list )
    2.     {
    3.         if( list.Count < 1 || list == null )
    4.         {
    5.             if( _Obj != null )
    6.             {
    7.                 // Destroy tower.
    8.                 _Obj.SetActive( false );
    9.                            return;
    10.             }
    11.         }
    12.     }
    Not sure why it's out of range, any ideas?

    Thanks.
     
  26. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    1. How large is your map?
    2. Is the map set up properly ? Can you get any paths?
    3. Sure your end and start position is within the map?
     
  27. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    I managed to work it out, thanks. One more question regarding the dynamic TD example.

    Is this function:

    Code (CSharp):
    1.     private void CheckRoute(List<Vector3> list)
    2.     {    
    3.         //If we get a list that is empty there is no path, and we blocked the road
    4.         //Then remove the last added tower!
    5.         if (list.Count < 1 || list == null)
    6.         {
    7.             if (towers.Count > 0)
    8.             {
    9.                 GameObject g = towers[towers.Count - 1];
    10.                 towers.RemoveAt(towers.Count - 1);
    11.                 Destroy(g);
    12.             }
    13.         }
    14.     }
    The one that decides if the path is blocked? How does it work? Most the first if statement, my list is always empty, what list it it that gets passed in?

    Is there another way to check it the path from the start position to the end position is valid? And also, what about checking from each enemy to the end position, especially since you could potentially block an enemy in a group of towers if you only check the start to end position.

    Thanks.
     
  28. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The first if statement checks if an empty list got returned which means that there is no valid path from A to B.
    If there is no valid path we remove the last tower we put down as it is placed at an invalid position.

    If your gameplay allows for blocking the AI you should just do the same. Create you own logic in a method just like this.
     
  29. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    But what is the list? Where does it come from?

    I'm assuming this line runs the CheckRoute function, but it passes in no list?

    Code (CSharp):
    1.             Pathfinder.Instance.InsertInQueue(start.transform.position, end.transform.position, CheckRoute);
     
  30. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    Hi,

    Can i recreate the collision map for a new object with a collider added to the scene ? If i do so once, will that create a big spike or will hardly be noticable ?

    Thanks
     
  31. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    That is not a good idea. Use the dynamic map update
     
  32. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    The list is the path (Vector3 positions) which is returned. If its empty there is no path.
    And yes that is the function. So if you want to check for an enemy for example then just use the enemys position as start position and change CheckRoute to your own custom method
     
  33. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    Thanks, i will check it out.
     
  34. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Check the PDF.
     
  35. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Okay thanks.

    Now I have it so you cannot block any of the enemies path also.

    The problem I'm having now is that when I try to block a path the first time it will not let me because list.Count = 0, however if I try to place a tower in the exact same position as I did before where it was blocked, it allows it and says list.Count = 59, or whatever.

    I have no idea why, any ideas at all?

    Cheers

    Cyp.
     
  36. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    You have to update the map with a dynamic change. Should be described in the pdf.
     
  37. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    I've been using your scripts from your dynamic td example, so I believe this is already done.
     
  38. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Well the td example is exactly that, an example. And only work for that specfic case. You need to write your own logic around it.
     
  39. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Right. I know that, but what I'm trying to achieve works in the example.
     
  40. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Well not sure i understand the problem then. Can you provide the code you are using?
     
  41. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Hello.

    I was looking at the Pathfinder.CreateMap() method, with the hope of being able to add a "margin" value to all items which are tagged/marked as obstacles. In this way i can have a detailed/low value for the TileSize, but have space around the edges of Obstacle blocks. I was unable to figure out an easy way to enable this. Should i simply increase the size of the box-collider for the object, beyond their visible bounds?

    Not expecting anything for a free asset, but suggestions or pointers would be great! :)

    Thank you,
    Jos
     
  42. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Yes that would more or less be the way to go as its created by raycasting.
     
    Jos-Yule likes this.
  43. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Thank you!
    J
     
  44. Gcolomb

    Gcolomb

    Joined:
    Aug 29, 2013
    Posts:
    5
    Hi,

    Just saw your plugins and I'm trying to figure it out.

    Did you ever implement it with PlayMaker?


    Thanks.
     
  45. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Nope never got around to do so sadly. But if you can code Actions for PlayerMaker yourself it should be really easy.
     
  46. liquify

    liquify

    Joined:
    Dec 9, 2014
    Posts:
    187
    Hi, first of all, thank you very much for this great script! Other pathfinding solutions, including Unity's built-in NavMesh, cannot constrain an object to move non-diagonally, but your Waypoint solution works very well for this.

    I just wanna ask about the waypoint Y Position and the character Y movement (jump) ability. To describe this:

    Suppose there are four waypoints with different Y Position (please see the image):
    - Waypoint 1 has Y Position with the value of 0.
    - Waypoint 2 has Y Position with the value of 0.
    - Waypoint 3 has Y Position with the value of 1.
    - Waypoint 4 has Y Position with the value of 2.

    The waypoints are connected to each other, in both directions, but not diagonally.

    For example, a character can only jump +1 unit.

    Suppose he wants to go from waypoint 1 to waypoint 4. Because he can only jump +1 unit, he should travel like below:
    1 --> 2 --> 3 --> 4

    But because waypoint 1 and waypoint 4 are connected, he travels directly from waypoint 1 to waypoint 4:
    1 --> 4

    How can I set different path for different characters, based on the character's jump ability?
    Like the example above, ideally the character should travel from 1 --> 2 --> 3 --> 4, because he only has jump +1 ability.
     

    Attached Files:

    Last edited: Jan 10, 2015
  47. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Right now you can only set possible height for the overall game (same rule for all agents). But you could add a float value to the path generation method that will change the possible height for a single agent. Thats more or less the only way.
     
  48. liquify

    liquify

    Joined:
    Dec 9, 2014
    Posts:
    187
    Is the path generation method the WaypointPathfinder.cs' FindPath() ? Or other method in other script?

    I notice that in the WaypointScene (the example scene for Waypoint system), if I click on the MeshCollider, the Path property of the WaypointPlayer script will be added with several elements. Is it possible to check the Y Position difference of these elements, before the elements are added into the Path list?
     
  49. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Yes FindPath() will call the needed methods to get a path. Follow that path and send a height value through those and use it. Might be a bit work.

    Cant remember much of about the waypoint system havent looked at it for a year or so :D Let me get back to you on that one hehe.
     
  50. liquify

    liquify

    Joined:
    Dec 9, 2014
    Posts:
    187
    I will try to add a height value to the FindPath() method, if I can understand it :D
    Anyway, thanks again for creating this script and for making it free...
    If you have time, please add this character jump feature to the Pro version, I'll definitely purchase it :)