A* Pathfinding stuffs
by Cinder Games · 12/24/2007 (7:57 pm) · 13 comments
So i'm rather bored and getting back to some pathfinding code for TGE. For my project i can't use pregenerated paths due to the fact this is for a battle system. With multiple characters moving around, can't have paths created ahead of time.
As stated in the title it's A* pathfinding using binary heaps. Currently you'll need to provide the code an array stating walkable areas and unwalkable areas, a start xy and end xy, and it will give you a path consisting of another array of sqaures that will be your path. From there you can dynamically generate a path using those squares converted to a vector to represent your "real world" coords.
I was curious how many people actually need such a setup? I may get around to releasing the code if others are interested.
[EDIT - Added Some Pics]



Here's some images of my nights work. It randomly generates an area of walkable, and not walkable areas. You can edit these as you wish with clicking and dragging. Then you enter pathfinding mode, where you click a start and end position. and wham. it generates a path.
So what use is this? well this grid i created was just for a personal graphical reference. But you can generate the "map data" from whatever method you choose to represent paths on whatever type of environment you are using.
So for me, i plan on having multiple characters running about, so for this to work well, i'd simply need to modify the map data each time a character moves to a new square. this way there won't be any intersecting paths between moving characters.
This pathfinding is very quick. my attempts at getting a time in MS just seems to give me a 0ms search time. maybe i'm doing it wrong.
subvoicestudios.com/~ramensama/Pathfinding_Test_1.0.zip
By default it will generate a map on it's own, and put you into pathfind mode, so you can start clicking and right clicking. if you want to modify the map, open the console and type PathFindMode();
As stated in the title it's A* pathfinding using binary heaps. Currently you'll need to provide the code an array stating walkable areas and unwalkable areas, a start xy and end xy, and it will give you a path consisting of another array of sqaures that will be your path. From there you can dynamically generate a path using those squares converted to a vector to represent your "real world" coords.
I was curious how many people actually need such a setup? I may get around to releasing the code if others are interested.
[EDIT - Added Some Pics]



Here's some images of my nights work. It randomly generates an area of walkable, and not walkable areas. You can edit these as you wish with clicking and dragging. Then you enter pathfinding mode, where you click a start and end position. and wham. it generates a path.
So what use is this? well this grid i created was just for a personal graphical reference. But you can generate the "map data" from whatever method you choose to represent paths on whatever type of environment you are using.
So for me, i plan on having multiple characters running about, so for this to work well, i'd simply need to modify the map data each time a character moves to a new square. this way there won't be any intersecting paths between moving characters.
This pathfinding is very quick. my attempts at getting a time in MS just seems to give me a 0ms search time. maybe i'm doing it wrong.
subvoicestudios.com/~ramensama/Pathfinding_Test_1.0.zip
By default it will generate a map on it's own, and put you into pathfind mode, so you can start clicking and right clicking. if you want to modify the map, open the console and type PathFindMode();
About the author
#2
12/24/2007 (9:48 pm)
I'd like to see it!
#3
Get a higher resolution timer or profile it more than once. :) Same thing happened here.
Cool stuff you got there.
12/25/2007 (9:21 am)
Quote:
This pathfinding is very quick. my attempts at getting a time in MS just seems to give me a 0ms search time. maybe i'm doing it wrong.
Get a higher resolution timer or profile it more than once. :) Same thing happened here.
Cool stuff you got there.
#4
Here are some links for what we already have available:
Script implemented, slightly buggy, and not "true" A*
http://tdn.garagegames.com/wiki/TGB/Source/Pathfinding
"T2D" A-Star Pathfinding Extension
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
12/25/2007 (10:04 am)
There is an A* pathfinding resource for TGB that implements a version of A* on a TGB tilemap. I haven't tried it with the new version 1.6, but it compiled with 1.5. I remember people complaining about the performance, so if this can be applied to that and improve it, it would be awesome. I think a lot of TGB users could make use of this in their 2D games. I'll take a better look at the code when I get more free time. It seems very fast though. Thank you for sharing! Here are some links for what we already have available:
Script implemented, slightly buggy, and not "true" A*
http://tdn.garagegames.com/wiki/TGB/Source/Pathfinding
"T2D" A-Star Pathfinding Extension
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9711
#5
subvoicestudios.com/~ramensama/PathfindSource.zip
Here are the two source file's you'd need to add to your own project.
My next step will be to figure out how to pathfinding with objecters larger then one square. Any ideas?
12/25/2007 (3:32 pm)
I noticed the one for TGB before. But This is all TGE. its using code from http://www.policyalmanac.org/games/aStarTutorial.htm used with permission from the author for TGE. In his demo exe, the search time varies from 0-1ms as well.subvoicestudios.com/~ramensama/PathfindSource.zip
Here are the two source file's you'd need to add to your own project.
My next step will be to figure out how to pathfinding with objecters larger then one square. Any ideas?
#6
w00t ok, i solved it! it can now do 2x2 searching on the same grid. For me, this was my end result i was aiming for from the begining.
12/25/2007 (9:15 pm)
w00t ok, i solved it! it can now do 2x2 searching on the same grid. For me, this was my end result i was aiming for from the begining.
#7
maybe you could amend the algorithm to perform the single square search logic all the way up until you're near the destination so the character can still fit through narrow passage ways smaller than the destination object.
12/26/2007 (7:49 am)
nice work on solving the problem Ramen. I know youve been at this for awhile.maybe you could amend the algorithm to perform the single square search logic all the way up until you're near the destination so the character can still fit through narrow passage ways smaller than the destination object.
#8
> it can now do 2x2 searching on the same grid.
you mean the object finding a path is 2x2 ?
12/27/2007 (1:37 pm)
nice work as always, ramen.> it can now do 2x2 searching on the same grid.
you mean the object finding a path is 2x2 ?
#9

How it works is that even "objects" that are 2x2 and 3x3 in size will still move along the path 1 square at a time, finding a path the size of the object.
What this means is you can pathfind a human to run across and create a 1 meter wide path, and maybe have a SUV also use the same map data and not hit anything
12/27/2007 (2:53 pm)

How it works is that even "objects" that are 2x2 and 3x3 in size will still move along the path 1 square at a time, finding a path the size of the object.
What this means is you can pathfind a human to run across and create a 1 meter wide path, and maybe have a SUV also use the same map data and not hit anything
#10
12/27/2007 (3:11 pm)
gotcha. cool. nice graphic by the way!
#11
12/27/2007 (3:21 pm)
if i could figure out the math to it, i'd do some path smoothing... but for now it'll do the job i need. Now i can have monsters of various sizes runnig around trying to kill me.
#12
12/27/2007 (3:27 pm)
Also, not that it's that important, but it supports saving and loading "maps" So you can visually edit these maps and save them for later. Still not sure if there's a point. i'd actually like to convert this into some 3d objects for the world editor or something maybe. My goal isn't so much as pathfinding across maps as it it to navigate other moving characters, so i guess i'd better go ahead and start testing.
#13
10/30/2008 (4:07 pm)
Sounds very interesting - any chance of the source code for the "larger than 1x1" version? 
Torque 3D Owner Morrie