Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you make a PathFinder AI?

Asked by 10 years ago

My friend is trying to make a pathfinder AI, and he is really confused. Does anyone know how to make one. He has the following AI, but he can't make a pathfinder.

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Path finding is most easily formulated as graph search. In Euclidean space, the most efficient method to do this is A*.

Here is a general description of a graph (node) based approach to path finding. Since it can only find paths from nodes, the very first step is to identify the two nearest nodes at the ends.

A "node" is just a point in space which is "connected" to other nodes (connected in this context means that you can walk between them, in a straight line).

Start with the closest node to where you are at the beginning. Consider all nodes that are reachable from this place. Visit the best* choice to expand your search. Record that to get to that best node, you came from where you are.

Now that you have this new node in the list, evaluate all unvisited nodes to find the best one. Repeat the previous evaluation, and mark how you got to the new node. When you finally arrive at the destination node, you have just have to follow all of the markings of how you got to that node (previous node of this node, previous node of that node, ... until you get to the first).

*best: In Dijkstra's algorithm, "best" is just the smallest amount of time to walk to that node. That is, the "best" choice is the one which the sum of the distance traveled from start node to that node is the least (so mySum = parentSum + distance(parent,me)). This method fans out from the beginning but will always find optimal paths.

In a best-first, "best" is the distance from the current node to the final node. This method will go straight for the target and usually reach it very efficiently, but will not necessarily take an optimal path.

A* combines these two, by simply adding them. It can be shown that this is still guaranteed to be the fastest path (in Euclidean space) but will still be much, much faster than Dijkstra's method.

Ad
Log in to vote
0
Answered by
m0rgoth 75
10 years ago

I would say that it really just depends on what it is for. BlueTaslem gave an excellent summary of a general AI that can walk through a grid. I would recommend creating more dynamic structures for AI depending on the environments they are in. For example, I created this AI for pathfinding in a city. This city had a set structure with set shapes and common nodes, so certain patterns could be applied.

Answer this question