qiao / PathFinding.js

A comprehensive path-finding library for grid based games
http://qiao.github.io/PathFinding.js/visual/
8.41k stars 1.31k forks source link

3D Pathfinding Demos or Documentations? #213

Open evandarcy opened 1 year ago

evandarcy commented 1 year ago

Hey @schteppe, I am really curious about your fork.

At the moment this is the approach I am taking:

var grid = new Grid(gridWidth, gridHeight);
grid.setWalkableAt(x, y, true); // Set player position as walkable
var path = finder.findPath(startX, startY, endX, endY, grid);

I would like to extend this code to work in a 3D environment, how could I use your fork to achieve something like this? Are there some extra steps I would need to take?

If there are any demos or documentation specific to your fork, I would love to see them!

Thank you!

brean commented 1 year ago

Hey @evandarcy , What do you mean with 3D-environment? Flying vehicles? That's possible but it would require you to implement a different form of grid (with a 3rd z-value), the algorithms itself work on any graph. If you just want to use 3D environment but 2D pathfinder (e.g. using THREE.js) take a look at https://github.com/donmccurdy/three-pathfinding

evandarcy commented 1 year ago

Hey @brean,

Imagine you have 3D environment that takes the form of a multi-level building. On each floor of the building, there are different layouts of obstacles that are considered "non walkable" nodes. You will end up with multiple instances of the same (x,z) coordinates for each y level of the building that may have varying "walkable" or "non walkable" values for each coordinate.

I am wondering if the fork by @schteppe is intended for a scenario like that or should I be coming up with my own solution.

My concern with https://github.com/donmccurdy/three-pathfinding is that I would require the pathfinding to work in a procedural 3D environment, but maybe I could look at creating a navmesh using a tool like https://github.com/but0n/recastCLI.js

brean commented 1 year ago

hey evandarcy.

What you describe I would call multi-level path finding which would be less complex then real 3D where the agent could go in every direction (think of a quadcopter or an underwater vehicle navigating). I implemented this multi-level approach in python for python-pathfinding a few weeks ago by having a "world" instead of one grid with multiple grids inside, instead of just one grid and then having "portals"(doors/elevators/steps/...) between the grids. It was actually very easy to implement (just a custom function that returns the neighbors): https://github.com/brean/python-pathfinding/blob/main/pathfinding/core/world.py (If you like to implement "stairs" with different distance-costs then for example "elevators" you would also need to implement a custom cost-function but I didn't do that in python-pathfinding).