mikewesthad / navmesh

A plugin for path-finding in JS using navmeshes, with wrappers for Phaser 3 and Phaser 2
MIT License
355 stars 40 forks source link

how to get a random point on navmesh #63

Open orion3dgames opened 1 year ago

orion3dgames commented 1 year ago

Hi there,

Thanks so much for a great library,

I'm trying to get a random point on the navmesh, is this someting possible? And what would be the best way about it?

I know this is a not issue as such, but I have no idea where to ask this question, and it could be a feature? :)

jorbascrumps commented 1 year ago

If you're using Phaser, you could use Phaser.Geom.Rectangle#getRandomPoint to get a random position and then use NavMesh#isPointInMesh to see if it's inside the navigable area. Otherwise you could reverse engineer the Phaser implementation as it's rather straight forward.