Hi there, I apologize for the late reply. I’m going to mention you too, @EternalEthel, because I apologize for replying so late, after four years. (I’m not very active on here or Roblox in general anymore)
Anyway, before I answer your question, I would like to address a few things I haven’t mentioned in this open-source game.
Efficiency
When I made this game, I was just starting to learn about pathfinding algorithms. I did not intend to write all those algorithms for the sole purpose of putting them together into an open-source simulation(that happened later on when a friend approached me with the idea).
The main issue is that the algorithms are not as optimized as they should be. They use way more memory than necessary, and the path reconstruction is particularly inefficient. It’s storing more information(all parent nodes) than it should, which isn’t the most efficient way to backtrack in 2D. What it should’ve done is overwrite the grid with the cardinal directions of where each node was explored from. This meant you can easily reconstruct the path by following the parent without using extra memory(because you are just overwriting your existing grid). If this interests you, you can probably find some resources online on this.
Unweighted Grid
Some algorithms in the simulation don’t particularly show their strengths(and weaknesses) because of how the grid is constructed. You can easily see this by trying out both Dijkstra’s and BFS on the same grid. Spoiler: They will behave the same way.
This happens because the grid is unweighted, or in other words, the cost of each node is the same. Going to an adjacent node costs the same. This means that Dijkstra’s algorithm, which was made specifically for weighted graphs, behaves the same as BFS on unweighted graphs. I’m surprised no one has pointed this out after a couple of years.
Pathfinding in 3D
Now, before I answer your question, I want to mention that I won’t go into the details on this, but rather give you some guidelines on how to approach this.
First of all, do you need a 3D version of this? Now, this might sound like a dumb question, but think it through because in a lot of scenarios, you can just use a 2D grid. If you have NPCs that only move in the same plane, that’s just a 2D solution.
Once you answer that question, you should think about how to convert your game into a grid. There are many ways to do this, and some are more efficient than others. Some people like to use quadtrees/octrees, while others find that just splitting their game into fixed chunks works.
Finding fast yet accurate ways of constructing a grid is essential to make sure your pathfinding algorithm works efficiently. Otherwise, you are better off just using Roblox PathfindingService.
To give you an example, I’ll use @Ultraw’s Restaurant Tycoon 2. I chose this particularly because of the way the building system is designed, and this is one of the cases where making your pathfinding algorithm can show some benefit. Just to be clear, I’m not saying that Restaurant Tycoon 2 uses a custom pathfinding algorithm(I don’t know that), but the game is a good example for my point.
In the image above, you can see how the floor is split into fixed chunks, which can easily be turned into a 2D array(this is most intuitive, but you can also explore adjacency list representations) where each element is the state or cost of each chunk. Since you want to make sure your 2D array is up to date with what you see in the game, you would update this array every time a player placed new furniture.
Once you have a 2D array, using a pathfinding algorithm is pretty much trivial after that. There are lots of tutorials, pseudocode, and other information online that you can use for this part.
Anyway, I hope this helps guide you in the right direction. If you have any questions, I’m happy to help, although I can’t guarantee when I’ll reply
.