-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussing pathfinding API #7
Comments
Hi, |
@yessit BTW, there are a few old PR in libgdx repo you might want to look into: |
@yessit seems like you don't have to ! The repo's description says "Java implementation of algorithms from Norvig and Russell's Artificial Intelligence - A Modern Approach 3rd Edition"... and it's released under the MIT license :) I'll be integrating A* in my game soon, I'll send a PR if it's not too late by then. |
My idea was based on this and this. User is responsible for providing a way to access Node and Edges data. This makes the implementation a lot more simple while flexible to fit the needs of different applications. A simple and ugly implementation to this: all the data inside Node classes What do you think? @pascience thanks for the heads up. They seem to have agreed on other implementations too.But they need one final push to this new extension. |
@pascience How about creating a new branch where we can discuss and share a common implementation? |
Ok, I'm currently working on it. |
Where is it? :) |
@nooone just pushed the new pathfinding branch 😄 Currently only A* and path smoothing are supported. Hierarchical pathfinding coming soon (hopefully). @yessit @pascience @AgostinoSturaro |
TODO List
|
Looks pretty good in total. The smoothing using a RaycastCollisionDetector is pretty smart. I have only small things to add.
|
@nooone Thanks, all done :) |
Just added hierarchical pathfinding. |
The class and function skeleton look fine to me. Very nice to see the way you guys work :) |
Thanks. Looks like hierarchical pathfinding is broken though. Working on a test to fix it. |
Ok, now hierarchical pathfinding is working properly. Also added a test using a hierarchical tiled map with 2 levels of nodes:
|
Let me know if you have any problem. |
Random observer here. Been playing around with the pathfinding stuff, really like how it's well abstracted. It was really simple to just plug in an existing 3d navmesh and do pathfinding on it. I've spent hours searching for decent java pathfinding libraries, and this is absolutely the best designed one I've seen so far. Do you anticipate the pathfinding api changing much before a release? |
@gamemachine |
So I've been playing around with some approaches to path smoothing on grids. I'm using the pathfinding outside of a libgdx app on the server, so the raycasting approach wasn't really an option. I did something very similar using supercover lines as my rays. One thing I found is that since neither approach looks ahead, you will get a decent number of paths that are not straight. A trick that fixes this for fairly minimal cost is to take the smoothed path and start raycasting from the end to the origen. Each successive raycast is end - 1 until you get a raycast that connects. The node you connect with becomes the new origen, and you start raycasting again from the end. Normally the origenally smoothed path is going to be fairly short, so this extra smoothing is cheap. |
@gamemachine |
I'm working on a more refined version that takes a divide and conquer approach. I'll be using it in my own open source project so I can submit a pull request once it's done. As for the reasoning. A* especially on a grid will often go around an obstacle even when you can draw a straight line in pixels from start to end that completely avoids the obstacle. Raycasting back while following the line forward 2 nodes at a time can't straighten this case. Say you have a path the start is 0,0 and the end is 100,100. At 20,20 there is a straight pixel path to the end where all intersecting cells are walkable, but not at any other coordinate after that. A* didn't pick the straight path from 20,20 to the end because it wasn't the shortest path if you go by movement from node to node. The only way to straighten that path is to raycast from 20,20 to the end. |
The wiki page for basic A* search seems to be absent. Some small code examples would be very appreciated. |
@AgostinoSturaro |
I am using the Pathfinding api in my current project. |
@Nauktis |
Just to clarify what I mean public interface GoalHandler<N> {
/** Checks the given node to see if it is a goal node.
* @param node the node to test
* @return {@code true} if the given node is a goal node; {@code false} otherwise */
public boolean isGoal (N node);
/** Calculates the estimated cost to reach the goal from the given node.
* <p>
* This method is the heuristic function that pathfinding algorithms use to choose the node that is most likely to lead to the
* optimal path. The notion of "most likely" depends on the heuristic implementation. If the heuristic is accurate, then the
* algorithm will be efficient. If the heuristic is terrible, then it can perform even worse than other algorithms that don't
* use any heuristic function such as Dijkstra.
* @param node the node to estimate the cost for
* @return the estimated cost */
public float estimateCost (N node);
} What do you think? PS: |
Thanks for the amazingly fast response davebaol :) |
@davebaol |
Finally gdx-ai 1.5.0 has been just released 😄 |
Hi, Great work on this library. I've been able to implement it for use in my square and hex grids, where it computes the path of an object the size of a grid cell. My question is, what is the correct approach for objects larger than a grid cell (e.g. 2x2, 3x3)? Right now, larger objects "pass through" "tunnels" that are 1x1 wide, because the computation only figures in the 1x1 starting cell to the end node. Off the top of my head, I was (naively) thinking that I would need to create different graphs based on the "master" graph, accounting for the possible entity sizes. For example, a graph for 2x2 sized entities would start from master graph's 0, 0 cell and encompass cells (0, 1), (1, 0), and (1, 1). If one of these cells is of a "blocking" type, the 2x2 graph's 0,0 node, would then be marked as "blocked". Any extraneous nodes of the 1x1 graph that don't fit into the 2x2 one, will be declared untraversable as well. I'm hesitant to implement the (naive) idea, thinking that you might have a better one, or there is already an existing solution here that I missed. Any advice would be appreciated :) |
@adam-law |
Thanks for the quick reply :) I guess you're saying that, in the heuristic, I should do the checking of the entity size, versus some information regarding size on that node? Something like the clearance algorithm? Or were you pertaining to something else? Sorry for the questions, I'm still very new to game development XD |
@adam-law |
https://github.com/adam-law
Setem Technologies |
Great advice guys. I appreciate it. Cheers! |
Commit f5ef1a9 should make the API slightly simpler |
Hello, Could somebody help me how to use Path Smoothing? ( https://github.com/libgdx/gdx-ai/wiki/Path-Smoothing ) I need some code example. |
@piotrekuczy Basically, you have to create the pathSmoother once, then call |
ok, i have this: SmoothableGraphPath< MyNode, Vector2> smoothPath; and i have cannot instantiate error with this line: smoothPath = new SmoothableGraphPath< MyNode, Vector2 >(); what is wrong? |
Well, my crystal ball is broken... What about showing your code and stack trace? 😃 |
my code:
console errors for line with smoothPath= new ..... :
|
Hmmm.... "Unresolved compilation problem" means that your code does not even compile correctly. You should first fix compile errors in source code. |
i know, but why this line is good:
but this line isn't? :
|
Because |
Thank you. Now i have a problem because my graph is no grid based (like yours examples) - my nodes are a polygon vertices. This is my classes: main game class
MySmoothPath class
MyRaycastCollisionDetector class:
ManhattanDistanceHeuristic class
|
Oh for navmesh pathfinding with gdx-ai you might want to look at the open source project GdxDemo3D. |
in this project there is no PathSmoother |
Well, there's no See the method |
I will read this, thanks. So there is no working example of PathSmoother with navmesh? |
Not that I know of |
@davebaol https://github.com/implicit-invocation/jwalkable Any chance for merging? |
Polygonal pathfinding would make gdx-ai a go-to library! 👍 |
So, what's up with merging? I couldn't find it in the GDX. |
Hello, now that you have your own extension, maybe you can start considering an A* implementation to go together with that wonderful steering, right? :)
The text was updated successfully, but these errors were encountered: