mikewesthad / navmesh

A plugin for path-finding in JS using navmeshes, with wrappers for Phaser 3 and Phaser 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Defining Navmesh from List of Unwalkable Areas

Cormanz opened this issue · comments

Hi there, I'm taking an interest in your library navmesh. It seems really good for pathfinding, but I have a question.

How would you use this to make a NavMesh from only the unwalkable areas?
I have a list of obstacles as polygons but I don't have the walkable areas, only the unwalkable areas.

Could this library create a Navmesh defined from the unwalkable areas instead of the walkable areas?

I actually wrote a function to do this if it can be of any help.
I think that the output grid is far from optimal however.

Sorry - I've been traveling, so slow to respond to issues this month. I'll look into this issue this week. Thanks for sharing that generate @SylvainBreton!

sry, the link is dead following a merge request : here is a new one (once again far from optimal coding):
https://gitlab.com/eternal-twin/mush/mush/-/blob/develop/App/src/game/scenes/daedalusScene.ts

A couple thoughts:

  • I'd recommend checking out @SylvainBreton's example.
  • If you are using a tilemap, or if your world can be represented on a grid, then you could try out the built-in navmesh/phaser3-navmesh API for generating the navmesh from a grid.
  • Beyond that, you'll have to roll your own solution for now. There are JS decomposition libraries out (like poly2tri) there that implement different approaches, e.g. a good algorithm might be constrained delaunay triangulation. It sounds like you want to define a poly for your whole map, then use the obstacles to define holes and then feed it into a decomposition algorithm that supports holes.
  • It's more tedious, but you can always generate meshes by hand via Tiled.

It's on the roadmap to support more navmesh generation techniques, but time has been limited. PRs welcome if you feel like contributing!