Public Group

# Is there anything faster than A* pathing?

This topic is 2048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Really the title says what I'm asking- clear, concise and correct.

##### Share on other sites

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.

##### Share on other sites

Things faster than A* include, for example, summing two numbers, calculating a dot product or doing nothing at all. Most problems have many good solutions, and the best one must be picked by you depending on the specifics. And even better than a good solution is avoiding the problem altogether, which is also sometimes possible.

Edited by powly k

##### Share on other sites

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.

I was thinking a floodfill type to determine a solution and then A* only the nodes floodfill evaluated when finding the target.

##### Share on other sites

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.

If your data is static enough you can just pre-calculate 'islands' so that you never do any work evaluating impossible paths.

For the OP, the key is really understanding your problem domain. E.g. On a simple top-down driving game, your 'pathfinding' could be as simple as caching a direction/speed vector for every point on your map. In a more general case though, A* is pretty hard to beat.

##### Share on other sites
A*'s strong point is that its guaranteed to give you a correct answer.

as i recall, it (and its variations) and slower algo's such as Dijkstra's and breadth/depth first are the only ones guaranteed to work.

that floodfill trick Ed mentioned sounds like a good idea, where warranted.

obviously there are many things you could do (including nothing) that would run faster. but they aren't guaranteed to work, the way A* and its brethren are.

I recall reading an article about something called jump-A* or something like that. probably one of the speedups in the list Hodgman mentioned. there they seemed to be speeding up things by having the search "jump" across open expanses of empty map.

personally, i've always suspected that a pathfinding AI that modeled human behavior might be a good approach, especially in those cases where A* and its ilk have difficulties, such as very big maps, lots of units, dynamic environments, areas of the map that are hidden or unknown, limited pathfinding range, etc.  i mean think about it, when we humans want to calculate a path, we don't star making maps and lists of the room in order to figure out how to get to the fridge.  or maybe we do. what we do IS similar, in that we think in terms of the goal (range to target in A*). and then we start plotting the intervening objects.  so we don't create a whole map of the room.  our map is just us at point A, and the goal at point B, and a line connecting them. then we start adding intervening objects, and adjusting the path as needed to go around them. we add objects until all intervening objects have been added, or until we add an object that makes the goal unreachable.

adding an object may cause the path to change drastically (the local maxima problem). we're 3/4 of the way to the goal, then an object comes along that means the shortest path around the objects is now going entirely the other way.  humans probably also do something like add large obstacles to the map first. for convex obstacles, this would work well. for concave we probably enclose them mentally in convex shapes and solve as usual.  and we do it at 2 levels. i'm in room or area A, the goal is in room or area B. at the low level, how do i get out of room A, and in general at the low level, navigation across a given area. then at the high level, we calculate a path through rooms or areas from area A to area B.

implementing the low level would be pretty easy. you already have an A* map, and a start point and a goal point. you cast a ray from start to goal. if it hits a BBox on the map, you figure out whether its shorter to go left or right. given the point of impact and the BBox location and size, this is trivial. you move your ray casting point to that corner,and record that corner as a navpoint on your calculated path. then you cast a ray from there to the goal and repeat the process until you cast a ray and reach the goal. the list of navpoints generated describes the line path around the edges of the BBox obstacles.

but then you still have the problem of local maxima. i'm in a room with a door to the south. my goal is to the north. any attempt to go north without leaving the room first results in a wall to the north blocking me - a dead end - i'm boxed in.   there i suppose we humans do some sort of "is the goal in my room?" check first. if the goal is not in the same "area" we are, we go to high level (room) navigation to get to the correct area, then raycast our way from the door to the goal.

then the question is how does the high level room navigation work?
Edited by Norman Barrows

##### Share on other sites

A* is really one of the fastest there are, but it can be used inefficiently, for instance imagine you have 5 actors standing more or less in the same place and they all want to go to the same destination, do you run A* for all 5 actors? if so, that is inefficient, but not because A* isn't fast enough.

Another example, imagine that in order to get from A to B you must traverse a room from one door to another walking around a table that is in between both doors, barring the prescence of a mobile obstacle, such as another actor, the path within that room will always be the same, are you running A* to find out what it is every time you need to traverse that room? also wasteful, it can be pre-computed on level design and saved into the room information.

There are tens or hundreds of tricks like these that improve performance without resorting to an algorithm other than A*, A* is fast enough, reliable, well known and documented and simple to implement for most (but not all) pathfinding requirements, its all about context.

Your question is "clear, concise and correct." but incomplete, why do you feel you need a faster algorithm? what are you using A* for? what is the context?

##### Share on other sites
I was going to note Rectangular Symmetry Reduction, but that seems to already be mentioned in the link Hodgman posted.

##### Share on other sites

Your question is "clear, concise and correct." but incomplete, why do you feel you need a faster algorithm? what are you using A* for? what is the context?

I'm actually not going to use it at all.

I was looking at another devs blog and saw he used A* in his rts so I looked it up and watched a couple videos about it and was curious how the community felt about it and if there was something more epic out there.

The context is a mobile tank maze game for android which is a rewrite/upgrade to my first game to bring it a bit more modern. I'm drawing 225 blocks, background, shadows,  up to 200 rounds of ammo, up to 50 rockets, all the interface buttons and displays, and tracking up to ~50 enemies

-on a phone or tablet.

Those numbers are tentitive so if all continues as it is now on my testing device, I might bump those numbers up- at least the number of enemies because at full power up, my bullets and rockets pour out of my vehicle like water and cut a smexy path of destruction. And I will need my foes to catch my wrath.

Screenshot here.

Edited by latch

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013457
×