The thing to rememer about A* is that it simply does not care how your world is connected. It's happy searching through a square grid, a hex grid, or even something totally bizarre, like a square grid with teleporters.
Essentially, to run A*, you need three pieces:
- A distance heuristic. This is a function that tells you approximately how far you are from the goal, and the one restriction on it is that for A* to work correctly, it can never *over*estimate the distance (this one is the reason that teleporters would be a pain, since you need to factor them in to avoid surprise shortcuts).
- A way to tell which nodes you've already visited. Lookups need to be fast, because you'll be using this a lot.
- A way to get the possible next steps from a given node, including weights.
Since A* doesn't care how the world is connected, you can feed it a 3D world just by adjusting those three key pieces:
- Pretty easy. Instead of 2D distance, calculate 3D distance. If there are fairly few connections between levels, you might want to factor them in to this part.
- This works pretty similar to before. Since you only need one for the entire algorithm, you were probably using a 2D array before, so just add the third dimension. Memory usage will go up a lot, but not horrendously.
- Again, pretty easy. Just check for and add any valid cross-Z-level moves to the list.
Or you can do a multi-phase search, like Veroule suggested. The advantage here is that once you reach all the stairs on a level, you can stop thinking about that level. The disadvantage is that you *have to* reach all the stairs on each level before you can continue. A single, hard-to-reach stair on one level will make your running time spike, because you have to follow the path its entire distance before you can continue, as opposed to the direct A* where if it's longer than the correct path, it will never be followed.
A hybrid solution would be to run standard 3D A*, but whenever you hit a stair, check to see if all the stairs on that level have been reached. If so, mark it as done, and whenever you pop a node on that level, just discard it and continue onwards. For bonus points, also mark any levels further from the goal as done, since you'd still have to go through the completed level, and you already know the best paths for its stairs.