Skip to main content
GameDev.net gamedev.net
🔒 Locked

simple pathfinding

Started by BeanDog May 18, 2000 at 12:58 PM 20 replies 3k views
Original Post
BeanDog
BeanDog
I''ve got an array of about 256x256, which stores, among other things, an array of bool''s that say whether or not my unit can move there. How can I make a very good pathfinder from any one spot to any other? ~BenDilts( NULL* AIexperience); Bean Dog
WitchLord
WitchLord
You''ll want to look into the algorithm called A* (pronounced ''a star''). It is a farly simple yet powerful pathfinding algorithms. There are better algorithms but they are usually modifications to A*, and they are only needed for very long paths.

You can find a lot of info on A* at Amit''s Game Programming Information.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
BeanDog
BeanDog
thanks for the tip.

a* seems way overkill for what I''m doing, though. I am doing a real time strategy game (very early in development). I just got my creatures to move correctly, but (go figure) they don''t go around stuff by themselves. So I was thinking, I could do a really simple algorithm, since my units can either go onto a space or not, and I store my terrain-blocked map squares separate from my unit-blocked ones. I could just do a search straight from the unit to the destination. If the search path hits some terrain, it SPLITS into two other searches going on simultaneously, one going left and one going right, and so on. If two paths ever cross, or a path hits where another has already gone, they will be eliminated. This will repeat until either the destination is reached by one path or all are dead-ended.

This may sound complicated, but it may be easier than it appears. This will only be done once per time that the unit is directed to a new destination, so it won''t slow down the game significantly. I''ll do a one-step-at-a-time procedure if it runs into another unit or building.

Any comments or suggestions?

~BenDilts( void );
bogdanontanu
bogdanontanu
I know a MUCH BETTER algorithm then A* one....

but cant tell you much because its secret...as it will be incorporated in may new release of a RTS...

All i can tell is that is a better algorithm...(but not faster than yours...
yours above is the fastest...but also has some problems in a labirnth

I may be able to speak after game release...
obysoft
BeanDog
BeanDog
Well, thanks a TON for the info, retard. I was all excited that I got a message, and it was just you bragging your cajones off. Get a life.

WitchLord
WitchLord
BeanDog, your search algorithm will work. I believe it is called either depth-first search or breadth-first search depending on how you implement it. I think you should go with that so that you can get on with your game, but later on I would recommend A* as I believe it is the best for what you are doing. And no it is not overkill, it can bring down the pathfinding processing time to perhaps 10% (educated guess) maybe even less. And that in turn allows your game to build intelligent paths for goals at farther distances.

- WitchLord

Edited by - WitchLord on May 19, 2000 8:11:47 PM
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
BeanDog
BeanDog
OK, I''ve got a basic pathfinder working, but it is so SLOW! How am I going to get the more-complex a* to work if a simple approach works so slowly? How would I choose where the waypoints would be? I couldn''t use every block in a 128x128 grid!
Kylotan
Kylotan
quote:
Original post by BeanDog

OK, I''ve got a basic pathfinder working, but it is so SLOW! How am I going to get the more-complex a* to work if a simple approach works so slowly? How would I choose where the waypoints would be? I couldn''t use every block in a 128x128 grid!


A* is a more complex algorithm but the complexity helps it be more efficient. As another example, bubble-sort is a ''simple'' algorithm but quicksort will beat it nearly every time. What you save on code, you lose on processing time, mainly.
BeanDog
BeanDog
Perhaps I should define "slowly". I direct 50 units 100 squares accurately in about .5 seconds. That is still too slow for a real-time game.
WitchLord
WitchLord
I think you should try to implement A* and see just how much faster it is.

Another way to speed up the pathfinding might be to divide you map into small areas that contain for example 8x8 squares, then you first use the pathfinding algorithm to find the way among these. After that you use the pathfinding on the squares in each of the areas to get the exact path.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Kylotan
Kylotan
Also, instead of trying to fulfill all pathfinding requests at once, consider doing it in 2 stages: the order to move a unit from A to B generates a Pathfinding request, which you add to a queue. Then elsewhere in your game loop, the Pathfinder picks off these requests and deals with them. You can then limit it to only dealing with 10 requests per frame, or limit it to only spending a certain number of milliseconds dealing with requests. That way, your frame rate / game speed won''t have to visibly drop. The only difference is that certain units will remain still for a little while longer, but this is rarely an issue when you have 50 moving at once.
baskuenen
baskuenen
Maybe a quadtree (or octree) is a good idea...?...!
bogdanontanu
bogdanontanu
Sorry i see u got it too hard...my prev message to u...

hmmm i just wanted to say that even if i cant tell u (because of contracts...not that i dont want to )
to open ur mind to diffrent approach than A* with everybody thinks is best but is not....

Now i feel like i have to help u a little so u dont get mad at me:

whatever algorithm u use....
1.First
u can use it once to find the path then store all points in a vector then use that vector to move units until eventually a obstacle is found...in this case redo the pathfind....
2.Second
Dont do "whatever algo u use" for all units at once...better do one unit at a cycle...
so if u have 50 units unit 1 will start then next cycle unit 2 will start...u get the picture....this will make units remain a little late....but ALL Realtime games make it one way or the other...

Hope this helps
Sorry again didnt wanted to make u mad....

Bogdan
obysoft
Hans
Hans
Check out my pathfinding algorithm. Totally precalculated and definitely the worlds fastest pathfinding algorithm .

http://www.kolumbus.fi/hannes.k/tip2b.htm

Well my algorithm isn''t maybe simple to implement, but it''s hell fast. It takes only one memory read to move a unit one step towards it''s goal, using almost optimal path!

The idea behind it is quite simple though and needs lots of thinking still, but you might be interested. Dynamicy is a problem with this algorithm, because everything is precalculated. However, it IS possible to make dynamic parts but it needs some extra work if there are dynamic parts on the route..

The algo can also solve any maze and no matter how complex map, equally fast.

-Hans
StrategicAlliance
StrategicAlliance
Hey,

Last year I did a project on this topic with a few friends for my course Datastructures & Algorithms II.

It features a state of the art report on holonomic motion planning with several basic algorithms.

There''s one drawback, the project is written in Dutch (sorry guys), but I''ve also added a Visual Basic program which should visualize what I do and the algorithms are open-source.

Let me know what you think about it!

******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************
****StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...****
StrategicAlliance
StrategicAlliance
Woops, you can access the page form my homepage of course, but here is the direct link:

http://www.softline.be/StrategicAlliance/RUG/MotionPlanning/

******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************
****StrategicAllianceOn the day we create intelligence and consciousness, mankind becomes God.On the day we create intelligence and consciousness, mankind becomes obsolete...****
BeanDog
BeanDog
OK, here''s how I do it. I have a search algorithm that goes directly toward the goal until it hits something. Then it splits up into 2 searches, going opposite directions around the obstacle. As soon as a dead end is it, that search is eliminated. This is a very fast method. When you first move a creature, I calculate the first about 50 squares in the path and store them in the creature itself. When it gets to the end of that 50, I calculate the next 50, etc until the unit gets to the destination. This is pretty darn fast, but not fast enough. I will try implementing how I will just do one per frame, but that will be a problem when the units get to the end of their 50-square process and have nowhere to go.

Thanks for all the advice, and when I have time I''ll check out your super-fast algorithm, Hans. I have a feeling it will be very memory- intensive, though, especially for large maps (256x256 and up).

~BenDilts( void );
BeanDog
BeanDog
OK, I think I get the idea of the region search. Only problem is, what happens when the path from one region to another is totally blocked by dynamic units?

Also, how would you calculate the arrow paths from each region to the surrounding ones if the regions aren''t convex?

Hey! I''ve got an idea. If your map is divided into regions, you only have to store the paths to each of the SURROUNDING regions, and store the paths (in regions) for the farther paths. That way, you would have to do maybe 3 memory checks (oh darn) per iteration, but you wouldn''t have to store all 500 values for arrows, just, say, 15. that would be 256x256x15, or less than a meg, plus a little for the paths to each region, 500x500 array (for the next region to go to from one region traveling to the destination region). You get my vision?

~BenDilts( void );
Chance
Chance
One way to do it would be to compute paths around obstacles as lines. Then store all the lines in a structure that has waypoints (points along the line) and connections to other lines. Then, to make something move anywhere in your world tell it to move along the lines. Doing it for all obstacles may be a bit excessive so my suggestion would be to compute the lines only around objects of a given (larger) size and use another solution for actually reaching the waypoints, because there may be a small obstacle between the thing you want to move and the nearest way-point.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.