Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / a* pathfinding

Author
Message
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 10th May 2006 18:31
(attatched)
I tried implementing A* methods as described here :
http://www.policyalmanac.org/games/aStarTutorial.htm
in DBP, I use a maze object with a limb called 'DEST' in the middle,supposed to be our destination to reach it with A*... I've achieved this however the route it chooses is rather strange and time consuming...
this is all I could come up with.I'm posting in the hope someone will see this and help improve it properly. thanks

A study done by William Speyer, who was a victim of prison rape in 1989, shows that 34% of [prison] rape victims released from prison become child molestors.

Attachments

Login to view attachments
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th May 2006 08:58
There's actually already a few A* algo's out now...

IanM's was the first, for DBC, then someone ported it to DBP.

I have one, which is slightly less generic than IanM's, but I personally think it's easier to use.

Then there's some others that I can't remember, etc, etc...

Have a search on the forum and see what you can find

Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
http://jt0.org
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 26th May 2006 09:34 Edited at: 26th May 2006 09:34
actually I already saw those,I will try to adapt them for objects and 3D environments one of these days...thanks for responding

A study done by William Speyer, who was a victim of prison rape in 1989, shows that 34% of [prison] rape victims released from prison become child molestors.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th May 2006 13:50
For 3D pathfinding, or 2D pathfinding with 3D objects?

Because 3D pathfinding adds a whole other element into the arena... In other words - Hard!

But, if you're meaning the other way, then just treat it as a 2D problem, and only move the objects on the X/Z axis, etc, which means that you can take any generic A* algo ( like mine or Ians, etc ), and use that straight out of the box for 3D objects moving on a 2D plain

Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
http://jt0.org
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th May 2006 15:12
@Yian,
I haven't forgotten you - It's just a particularly busy time at work ATM and I haven't spent any time on my own coding, not just yours ... I will get to it though.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th May 2006 15:38
Chapter 11 of my RTS tutorial discusses using Ian's library, its the easiest I think and includes several search methods.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 27th May 2006 10:52
Thanks guys and Ian no problem man!
now what I'm trying is using Ian's '2d' pathfinding in a 3d environment...it will still be 2d,ie in the xz plain..

A study done by William Speyer, who was a victim of prison rape in 1989, shows that 34% of [prison] rape victims released from prison become child molestors.
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 29th May 2006 05:50
I have very succesfully used Ian's pathfinding routines. Once you get everything sorted out, they work wonderfully

Xander Moser - Bolt Software - Firewall
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 29th May 2006 09:01 Edited at: 29th May 2006 16:23
I'll try again thx for that!
OK got it working! but the problem now is say I have a level object,how do I isolate the 'unwalkable' nodes/block/cells to store them in Ian's arrays? because I'm considering each single x/z coord as a cell.

A study done by William Speyer, who was a victim of prison rape in 1989, shows that 34% of [prison] rape victims released from prison become child molestors.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 31st May 2006 19:30
That's probably not a good idea.

You want to break your area up into a grid of decent size... Basically, about the size of your smallest 'player'/'unit'/'object', then use each one of those as a node.

Also, if you have large open area's, and you also have paths that are frequently used, you can use a multi-tier system where you make a number of A* area's, each with their own, decreasing number of cells.

For example:
Tier 1: Continents
Tier 2: States
Tier 3: Towns

A* from New York City -> Sydney
Tier 1: A* from America -> Australia
Tier 2: A* to NSW
Tier 3: A* to Sydney



Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
http://jt0.org
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Jun 2006 02:35
Yian, what do you mean exactly when you say 'because I'm considering each single x/z coord as a cell'?

Do you mean each cube in your map occupies a cell? If you are storing the whole map as a single object, then you could use INTERSECT object at each grid point to see if you hit the object, and if so, set the appropriate cell in the map.

@Jess, I have considered adding multiple maps to the library, but not different scales. How would you do what you suggest? For example, how would you know that the 'high-level' cell was actually crossable east to west without looking at the lower level detail of that cell?

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 3rd Jun 2006 10:45 Edited at: 3rd Jun 2006 10:46
Generally it's done offline.

Basically, you set up your Maps, give all the information to the A* algorithms, then run a system whereby popular tracks are recorded.
(That's simply done by lowering the cost of cells that have already been visited, and slowly, pattens will emerge)

Once this is complete, you can store that information along with the A* Map info, and load it in at run-time.

Then, using this 'frequent path' information, you can quickly get from one larger cell to the other, whilst still having the dynanic generation of the lower-level (more detailed) cells

'tis a bit of a neuscance(sp?) to run it offline, but for most games, the map doesn't change that often to require it to be dynamic, and most RTS games like StarCraft, etc, simply generate their A* algo's offline as the levels are made.

Also, if your terrain does change, then you can simply run quick checks along the lines of collision with an unexpected object, and then do a very fast path-find around that back onto the main track it was following.

There's lots of theory behind all of this, and I'm sure you, like me, have read most of it whilst developing your A* solution, but I can't reccomend GameDev.net and well-thought-out google searches enough!

Mull it over, and write it out on paper, do up some diagrams, and see if you can work out the systems to use... Pretty simple compared to the A* itself, but still complicated!

Jess.

Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
http://jt0.org
Yian
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Nicosia, Cyprus(the Greek half)
Posted: 3rd Jun 2006 18:31
Thanks for the replies Ian and Jess!
I finally made it,(attatched) but it has one little prob :
if you try and make the green ai sphere go to a target coord more than once, it will start from a strange position!
thanks again ,especially to Ian,your code rules!

A study done by William Speyer, who was a victim of prison rape in 1989, shows that 34% of [prison] rape victims released from prison become child molestors.

Attachments

Login to view attachments
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Jun 2006 20:54
It shouldn't be too hard adding a third dimension!
All you have to do is check all 26 surrounding cells instead of just 8. Only thing is, it would take much longer than 2d pathfinding.

There are three types of people, those that can count and those that can't.

Login to post a reply

Server time is: 2024-11-23 03:55:13
Your offset time is: 2024-11-23 03:55:13