1
\$\begingroup\$

For a final school project, I have implemented an A* algorithm for pathfinding across a tile graph. So far, it has worked far surpassing my expectations. However now I'm in the process of adding a bit more complexity to the level and I am not sure that tile graphs will cut it any longer.

I would like to add multiple floors, but for the sake of simplicity I will just create two floors. At the present moment, I have a 2D array of Nodes that represent the single floor in a level. I don't think this will be scalable any more to anything besides one floor. I am proposing a method to find paths across two floors using multiple clusters containing nodes for different sections of the map where some nodes are flagged as exit nodes that will lead to other clusters. Moreover exit nodes will also be marked for the ones that lead up stairs to a second floor. The heuristic cost of moving from one floor to another will be higher than if an agent was to simply move across the same level.

I'm thinking if an agent is trying to traverse from one path to the next, it first checks to see if the start node and exit node are on the same floor. If so, then the cost is simply the euclidean distance, otherwise it tries to find the path to the exit node on the cluster it's currently on, compute the path to that node, then compute the cost to the next exit node within that same cluster. Repeat ad nauseam.

So as a visual representation of this, this is a terrible representation of a floor plan. The only highlighted nodes are the exit nodes a busy cat

This is what I could come up with. Is there any other way besides searching through a ton of tiles and clustering? So far on a tile of 100X100 performance seems to be ok and not an issue. I have heard of using nav meshes, but I'm not entirely sure how to implement them in my project. Since this class is an advanced game development class, if we do use nav meshes, we need to create and implement our own and not use Unity's built in navmesh

\$\endgroup\$
  • 1
    \$\begingroup\$ I think you are on the right track. Efficient storage of your a* structures should keep performance and memory consumption within reasonable limits \$\endgroup\$ – Steven Mar 18 '15 at 2:00
  • \$\begingroup\$ Updated with some imagery \$\endgroup\$ – wolfdawn Mar 18 '15 at 14:29
3
\$\begingroup\$

Floors

meta-graph

Add a meta graph that explains the route between floor entrances / exits from floor x to floor y. The vertices are entrances / exits, the edge length is the path between an entrance A and an exit B in tiles on floor z. Each entrance / exit is connected by such weighted edges to all entrances and exits that are accessible from it through the floor(s) it's on.

Use your existing tile-graph A* per floor to find a path from an entrance to a desired exit. The path length will serve as the edge weight on the meta graph.

The meta graph will be used to quickly know, which entrances and exits need to be accesses but it's edges and their weights should be computed in advance. It explains through which floors you need to travel to get from floor x to floor b. The meta graph uses actual vertices and not tiles, in the sense that you need a list of neighbors for each vertex. A floor is not interesting as an object and is only used to connect it's entrances and exits with edges computed by the tile based path on each floor between them.

Remember that is an area on some floor is blocked, that floor should be logically divided to several sub-floors as entrances in one blocked sub-floor, do not allow direct access to other sub-floors.

Once you use the meta graph to figure out which floors or sub-floors you need to travel, you simply use the same tile based path-finding on each floor to get from entrance x to exit y.

\$\endgroup\$
  • \$\begingroup\$ Zehelvion, thanks a lot for your input. I followed your advice and after a bit of optimizing it works very well. \$\endgroup\$ – fryBender Mar 19 '15 at 18:04
  • \$\begingroup\$ You are very welcome. You can think of it as a sparse representation of the world map with cached information about longer paths. i.e you know that to get from room C to room A, you'll have to go through B cause that data is static and stored as the meta graph. \$\endgroup\$ – wolfdawn Mar 21 '15 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.