PDA

View Full Version : Pathfinder between levels



LOLFlash
September 25th, 2010, 12:04 AM
Hi all

I stuck on logic to make pathfinder work between levels.

If Im on 3-d floor and target on tenth how can I find a right way?


I have a pathfinder work on each level fine. It is point based levels with joins between point. each floor has points numbers starting from 1 (n1,n2,n3.......)

On each level I have 2 or 3 points entrance: stairs and elevators.


Is anyone get something like this working?

bluemagica
September 25th, 2010, 06:59 AM
Umm, in case you didn't know, there are no psychics or mind-readers on board at the moment(though some coding zombies are available), so if you need a proper answer try giving some info about the gameplay. What are these "levels"? is your game a platformer, or tds, or what?

If I understand your english correctly....you are saying your "pathfinder" works for each individual level, so whats the problem in running that in a loop till your player reaches the target?


If this is a platformer, then I would check if the NPC is near a stair or elevator, and use that to move to the next level, and repeat this till it reaches the target level.

LOLFlash
September 25th, 2010, 10:25 PM
Sory for English and thank you for your answer

Game has 100 points joined by lines (walkways) were player can walk from point to point to pick up something and can't stop a movement until reaches destination point. It moves strictly by lines (walkways) from point were player at this time to point were player pick to go.

if player in point n5 and picks to go to point n60 it walks trough 10 or 20 point using shortest path

Now I want to extend my game and make 20 more similar levels. To join levels I use portals from level to level.
so some points on level are portals;

To easy understand I called each level is a floor in building and portals are stairs and elevators.

Now If player at floor 3 point n25 and pick to go to floor 10 point n85 he should walk to elevator (point n10) take elevator to floor 10 (at floor 10 elevator at point n15) and walk from n15 to n85.

Looks easy:
if another floor->walk to elevator same floor after walk from elevator on destination floor to destination point.

But how to implement this easy?


there is no psychics and no wight in a path in my game.

bluemagica
September 25th, 2010, 10:34 PM
Sorry but I still don't really understand it....maybe you can provide some visuals?

if he can find points within the level, then I really don't see any problem with finding the elevator(which according to you is just another point), taking it to another level, and walking from there.

LOLFlash
September 25th, 2010, 11:57 PM
I have 3 elevators in different places and only one goes through all floors. 2 connected only some of the floors; And now stairs: Some floors don't have elevators but stairs only

TOdorus
September 26th, 2010, 09:56 AM
Just give the pathfinder what it needs. It needs to have a graph of connected nodes. It needs to know per node: what other nodes this node is connected to, what it costs to reach those nodes. This is the basic node. A* also needs something to base the heuristic on, but thats some additional info.

I'd precompute this after the level is loaded into your engine. Per portal/node store all paths/connections to the other portals. Store these paths on a portal object. Each connection should include: it's total cost, the floor it leads to.

Now a pathfinder can move through the same way it would move through nodes. Each portal can be seen as a node by the pathfinder.

LOLFlash
September 26th, 2010, 06:40 PM
Yes, TOdorus

I want to implement logic what you describe.

All my maps are stored in xml:
a.xml:

<nodes dbid="a" img="a.png">
<node id="a1" x="246" y="87" join="a7,a13,a23,a5"/>

............................
<node id="a5" x="499" y="107" join="a13,a4" stair="true"/>
<node id="a6" x="358" y="103" join="a3,a12" stair="true"/>
<node id="a7" x="279" y="115" join="a2,a1"/>
.................................................. ...........
</nodes>
b.xml

<nodes dbid="b" img="b.png">
<node id="b1" x="226" y="134" join="b6,b2" stair="true"/>
.................................................. ................
<node id="b4" x="402" y="189" join="b9,b5,b8,b11"/>
<node id="b5" x="390" y="189" join="b4"/>
<node id="b6" x="338" y="145" join="b11,b1" stair="true"/>
.................................................. ....
</nodes>
c.xml:

<nodes dbid="c" img="c.png">
<node id="c1" x="162" y="69" join="c2,c5,c11,c36,c37"/>
<node id="c2" x="135" y="180" join="c7,c1,c28"/>
<node id="c3" x="358" y="268" join="c6,c9,c4,c7,c8,c15,c16"/>
<node id="c4" x="402" y="135" join="c5,c6,c9,c3,c30"/>
.................................................. .....
<node id="c25" x="131" y="19" join="c17,c26,c32" stairs="true"/>
<node id="c26" x="29" y="76" join="c25,c11,c27" />
..................................................
<node id="c40" x="190" y="195" join="c38,c39,c6" stairs="true"/>

</nodes>


now I want to try to create one more z.xml where all connections made between floors

I'm doing it along with Map Builder this why it goes a little slow.

the path will be one more dynamically created xml from z.xml plus nodes from each level added at runtime.

I will show an example as soon as I create z.xml;

bluemagica
September 26th, 2010, 10:47 PM
read this: http://ai-depot.com/Tutorial/PathFinding.html

LOLFlash
September 27th, 2010, 10:10 AM
read this: http://ai-depot.com/Tutorial/PathFinding.html

thanks bluemagica

That what I need for my next step between levels.

Right now Im creating the interface to extract all nodes from all levels with properties stairs="true"

After I have all this nodes on screen I can join them by lines exactly as in tutorial you linked



Last thing to do to compute all available paths and compare the lengths

My z.xml:

<nodes dbid="z">
<node id="a5" x="499" y="0" join="c33"/>
<node id="a6" x="358" y="0" join="b1"/>
<node id="b1" x="226" y="80" join="a6,c11"/>
<node id="b6" x="338" y="80" join="c41"/>
<node id="c11" x="89" y="160" join="b1,d10"/>
<node id="c23" x="560" y="160" join="e10"/>
<node id="c33" x="421" y="160" join="a5,d11"/>
<node id="c41" x="243" y="160" join="e4,b6"/>
<node id="d8" x="442" y="240" join="f3"/>
<node id="d10" x="92" y="240" join="c11,e1"/>
<node id="d11" x="381" y="240" join="c33,f1"/>
<node id="e1" x="126" y="320" join="d10,f15"/>
<node id="e4" x="239" y="320" join="c41"/>
<node id="e5" x="227" y="320" join="f15"/>
<node id="e10" x="477" y="320" join="f8,c23"/>
<node id="f1" x="381" y="400" join="d11"/>
<node id="f3" x="448" y="400" join="d8"/>
<node id="f8" x="540" y="400" join="e10"/>
<node id="f15" x="268" y="400" join="e1,e5"/>
</nodes>

it shows interconnected nodes between levels
in id first letter represents floor name