2
\$\begingroup\$

I'm trying to come up with a way to pathfind on multiple levels. See image:

Path over a tiered landscape made of cubes

The orange walls would be considered a ladder, connecting you to the upper levels.

At first I thought of looking at it as though it were top down 2d, but I also need to be able to go under things at some point. How can I compute these paths?

\$\endgroup\$
2
1
\$\begingroup\$

Pathfinding in general is a graph searching problem. Since you are doing a grid based solution, Unity's nav mesh might not be what you want. You should look into A* search as there's many resources out there for it. Your graph has nodes and directional edges. Wherever your character can stand and occupy space is a node (each block face in your 3D world) and each edge is a link showing the character can move from one block face to the next. Assuming you know A* given your mention of 2D pathfinding, your problem boils down to, how can I get a graph representation of my game world. Assuming you have some data structure holding all the data of where blocks are placed (a 3D array with true/false for example) you can figure out how they are connected. 2 blocks adjacent to eachother on a flat surface means their top faces are linked in your navigation graph. A block placed above an adjacent block (i.e. 1 to the right and one up of another block) means the other block's top face connects to that block's side face IF there's a ladder. You can continue this logic until you have a script that builds a graph representation of your world. Then just run A*

\$\endgroup\$

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.