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.

Game Design Theory / Path finding through a maze :-y

Author
Message
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 15th Aug 2009 19:06 Edited at: 15th Aug 2009 21:01
My pathfinding script works around simple obstacles, but when it comes to a maze it goes through it to a certain point (the closest point to the object, but it can't go through). Heres a screeny:


Anyone who's proficient with A* care to help me out? I'm using the Euclidean distance formula if that helps.

EDIT: the 2 different coloured lines are different AIs with their own paths (they go to the same place!)


Your signature has been erased by a mod
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 16th Aug 2009 14:41 Edited at: 16th Aug 2009 14:43
it looks like all they are doing is pointing towards the box and moving forward, in which case you need to change that to a more advanced formula. I am not really the person to ask, though.

prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 16th Aug 2009 17:34
Well it tries to find the quickest path which is usually a straight line, but in the maze it isn't. Anyone know how to allow it to go the long way around?


Your signature has been erased by a mod
CoffeeGrunt
18
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 16th Aug 2009 21:13
Perhaps have them use raycasts to check if their movement vector is blocked...if that's possible, bear in mind I've only ever managed a basic FPS engine in DBP...

If I was ever given the opportunity to remove all the bad from the world, I wouldn't, because for there to be heroism, compassion and all that is good, there must also be all that is bad.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 16th Aug 2009 23:13
can I see the whole map?

prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 17th Aug 2009 00:30
Here it is. It is not going around


Your signature has been erased by a mod
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 17th Aug 2009 00:49
this probably wont be the most computationally efficient way but using permutations is a GREAT resource. if you have a 2d array that stores the map data (like 1 = wall, 0 = no wall) and then have the position of the starting and endpoints (2 = start, 3 = end), setup a recursive function that simulates all possible paths to the endpoint

might look something like this (pseudo code mind you):


this is called a 'brute force' method and uses a variation of the 'N-queens problem' algorithm. you could look into this... this method works because this was a type of project i had for a college course..

anyways, if you are uncomfortable with permutations or recursive functions, then maybe you can check into some sample code somewhere. but once you have this down, then you can optimize it. like determine which direction is shortest and so forth.

hope this helps!!


If at first you dont succeed, call it version 1.0.
Dark Dragon
18
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Aug 2009 04:13
Hey Homey, can you offer a bit more......explanation of teh code? I get what ur saying, but i dont quite get your "10101", if u catch my drift.....

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 17th Aug 2009 08:35
sure! if you could cut up your level into a 2 dimensional array like


these are just values stored in a 2d array. so you can have some constants that represents these values to avoid confusion.


so you might have...

if mapData(x+1, y) <> WALL and mapData(x+1, y) <> TAKEN
then mapData(x+1, y) = TAKEN
call function again

im going to post my code from my project. it is in C++ but hopefully you get the idea based off the code.


If at first you dont succeed, call it version 1.0.
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 17th Aug 2009 08:48
so here is my C++ code.



this is native C++ fyi... so, the idea is that we read in this file that represents a maze using string of characters '*' represents a wall and 'E' represents end point. given a starting position we find ALL possible routes and determine the shortest. we determine the shortest path for like 8 mazes in one file and this is all done in under a second (not sure the actual time)! so this is much faster than some would think. but there is optimizing that can be done im sure. but basically, as you traverse the 2d grid, if you have been in that spot before, you mark it with a '-'. when you reach the shortest path, you print out the path.

here is the step i take:

1) base case: (each recursive function MUST have a base case of some sort so it can exit out properly) if current position = 'E' and if shortest path is > than the current steps counted, shortest path = current steps counted. copy the grid array(or, the solution... this should be programmed differently. im copying the grid array because i am printing it out, you should not though..)

2) base case has not been met: if current position = '-' or '*' then return.

3) check all directions. if next move does not exceed array bounds, then mark that spot as taken or in this case '-'. call itself with new position. when function returns, take out the '-'. this is so it permeates all possibilities.

and that is pretty much how it works. i know it can be kind of a mind sore but its really efficient for what it does. so you can have a complex 3d level with complex geometry and the works but if you have a collision layer of the level representing primitives, like 16x16x16 unit cubes say, and store it into a 2d array. this will work.

questions? i know this is kind of hard to understand...it was for me.


If at first you dont succeed, call it version 1.0.
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 17th Aug 2009 08:57
also, although it might be slower than A*, this method can be a way of dynamically finding 'cover' given if you know how to calculate for it... since you are finding every possible path, maybe after each step you can pass in the magical calculation to see if it is efficient cover.. if anything, the ai can just store those 3d coords for cover that can be used for later use...like it learns the level in the progress of finding its destination...i have never tested this but it seems like it could work. downside is that you should probably run this function every so often as it might eat away fps if this is calculated for every game iteration for every active enemy.


If at first you dont succeed, call it version 1.0.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 17th Aug 2009 16:36
Ah so that is the way I'm gonna have to do it then. Having an array was not something I wanted to do (My maps have more than 1 floor and they can have curved surfaces, etc.)


Your signature has been erased by a mod
Dark Dragon
18
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Aug 2009 17:20
Ah,I see....

Quote: "questions? i know this is kind of hard to understand...it was for me."


Not at all, PERFECT. Well...........Yeah i do have one question, what do you do when you have say stairs or curved walls?

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 17th Aug 2009 18:42
bear in mind that this method is just one approach...

Well, here is something to consider...the smaller your 'collision' cubes, the bigger your array..but, the more accurate it may be. So, what happens when you take a high resolution picture and lower the resolution? it becomes pixelated or not as clear. that is kind of the same idea. so if you have a curved wall, you can still disect it into cubes but it wont necessarily look like a curve. this wont matter since it shouldnt be visible. in fact it might be better to have your collision cubes bigger than most walls because the ai will look less 'dumb' as it butts up against the wall all the time.

Quote: "what do you do when you have say stairs "


so the plot thickens... you can store all map data in one file. maybe something like this:



this will get a bit complex but here is my idea... so in a file you can either have the daunting task of manually writing this sort of file or make a simple editor for placing 'collision' cubes. but basically each room can have a name followed by its data for ai. a semicolon denotes the end of data. whenever you create your enemies, you can assign them a room name mentioned in one of the files whenever you place them in your level. whenever the player is in that room, you can activate those enemies and set your mapData array to that specific data in the file. in the file, a 6 could represent stairs.

but lets be real for a second, if your cubes are say 32x32x32 units and your level is no bigger than 5000x5000x5000 units. that leaves a 2d array of about 157x157..height shouldnt really matter at this point.. you can have an array like this:


that array size is about 25,000 bytes or 25 kilobytes...that is not much memory at all... of course the smaller your cubes, the more space it will take up. so technically you can store your whole map in one array! so you can have one big map for downstairs and another for upstairs (might have to be the same size which is really not much of a problem).

here is a sample of maybe a user defined type you could use..


so we have moved away from the 2d array and now have it as 1D. this could be easier for storing and retrieving data. when you read your data, if you can find a way to assign it its row and column, that could be way better. this datatype might eat up more memory but its not a bad sacrifice...

so now i know im leaking into something more advanced than what i started so questions welcome...


If at first you dont succeed, call it version 1.0.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Aug 2009 18:45 Edited at: 17th Aug 2009 18:47
Array based path finding (2D array I mean) needn't be a problem with curved walls, it just depends on how big you make the grid.

Really I think you have 2 options, make a 2D grid, so that maybe 3 grid points are the width of your maze paths and use a simple array based method. It's easy to get working, I made one using a flood fill style that I could post.

The other option is to place waypoints, lots of them interlinking, then you work out the path as a sequence of waypoints. Theres a really good article on waypoint AI with all sorts of support for cover and stuff, but it's not ideal for maze games, as you'd spend most of your time laying down waypoints.

http://www.cgf-ai.com/docs/straatman_remco_killzone_ai.pdf

The above article is one to print out and keep, very well written and easy to understand, definitely a consideration for FPS games.


Health, Ammo, and bacon and eggs!
Dark Dragon
18
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Aug 2009 19:19
Quote: "Well, here is something to consider...the smaller your 'collision' cubes, the bigger your array..but, the more accurate it may be. "


VERY nice point.

OK, I think I understand now! Thanks,Homey(Lol, its not my thread, yet i'm treating it like it...LOL.)!

Oh, and Van B - that article is quite informative, I want to write a FPS now..... Thanks, That IS a "Print and keep".

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 17th Aug 2009 20:08
Stop stealing my thread I feel unloved


Your signature has been erased by a mod
Dark Dragon
18
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 17th Aug 2009 20:27
Srry.....i'll crawl back into my coding cave now........

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 18th Aug 2009 00:02
Anyway, I've been trawling google and have found "navigation meshes". Would they be any use to me?


Your signature has been erased by a mod
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 18th Aug 2009 01:19
they seem to be a little advanced... its an interesting way of doing things but that would involve ALOT more coding. and you will pretty much have to create an editor for it. to be honest, i am not trying to say my way is the best way but, its probably best to learn to walk before you run. i think VanB and my approach is a reasonable beginning approach. this could evolve to this navigation mesh system... even with these navigation meshes, you will still need to have an algorithm to calculate the path from point a to point b and most likely determine obstacle avoidance within that path...


If at first you dont succeed, call it version 1.0.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 22nd Aug 2009 13:17
It doesn't matter now. I've fixed my A* All I have to do now is make it so it follows the path (all of the circles are the "closed list")


Your signature has been erased by a mod
heyufool1
17
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 22nd Aug 2009 19:44
Nice work prasoc! Just wondering, do you have to set each wall up some how or do you just throw a wall in there and it works?

Games are like life, they should never stand still.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 22nd Aug 2009 20:39
It uses sparky's to check collisions. Works fine All I need to do is make the level/maze and it goes around obstacles automatically


Your signature has been erased by a mod
heyufool1
17
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 22nd Aug 2009 21:03
Nice, good luck!

Games are like life, they should never stand still.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 23rd Aug 2009 01:38
I got it to find the path through a maze (apart from some slight collision problems where the path would go through a wall :S) But the main thing is that I have solved my thread's problem and it is really cool (the first algorithm I have implemented)


Your signature has been erased by a mod
Homey the Clown
22
Years of Service
User Offline
Joined: 4th Apr 2004
Location:
Posted: 28th Aug 2009 20:27 Edited at: 29th Aug 2009 00:06
congrats!

anyways, may i ask what method did you use to solve this? did you use the 2d array idea with permutations? just curious as im thinking of using that method down the road but not too sure how fast it will run on darkbasic pro...


If at first you dont succeed, call it version 1.0.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 30th Aug 2009 02:21
What it does (in essence) is goes in directions and checks to see if that direction has an object there (sparky's raycasting), and if it does, it deletes it from the open list. That is the basis for my 3d A*, it doesn't use a pre-compiled array of the level and I could put any level in and it will find a path.


Your signature has been erased by a mod
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Sep 2009 02:02
looks great prasoc,
Am I right in thinking you are casting a ray say 5 units in one direction at a time?
so if there's no array how are you storing the path?
I notice it goes through walls sometimes when they are at strange angles, what causes that and have you managed to solve the problem?
This is a great help as I'm working on my own pathfinding at the moment.

TGC Forum - converting error messages into sarcasm since 2002.
prasoc
17
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 16th Sep 2009 00:09
I have fixed where it can go through walls. What it does is when it tries to find a path back through the parents, it checks for collision as well, thus missing out obstacles. And yes I am ray casting so I can put my bot into ANY maze, level etc. with no preplanning (tis good ). What I have made it do now is follow the player (I have implemented it actually into my engine now), and I found a few niggles which I have fixed when it walks the path it finds.


Your signature has been erased by a mod

Login to post a reply

Server time is: 2026-06-11 14:45:49
Your offset time is: 2026-06-11 14:45:49