donmccurdy / three-pathfinding

Navigation mesh utilities for three.js, based on PatrolJS.
https://three-pathfinding.donmccurdy.com/
MIT License
1.22k stars 135 forks source link

Add a support for path margin ("edges" and "walls") #245

Closed FrameMuse closed 4 months ago

FrameMuse commented 4 months ago

I've been researching how to add a safe-margin to my units, I could find much information since it's all related to Unity, which has its own built-in scripts.

I also found something about altering the heuristic, but I don't understand how. There is an advice to "see" for closest point of "wall" or "edge", but I don't understand how.

So could you help me with that, I'm not sure how to add this, I think there is no way with current API to do that.

I feel like this is worth adding to the library eventually.

donmccurdy commented 4 months ago

Recast (a navmesh generator) has an option built in, I think it's called "agent size". The idea is to leave some padding around the navmesh, like what you see here:

CleanShot 2024-06-22 at 12 30 01@2x

Source: https://www.gamedev.net/tutorials/programming/artificial-intelligence/implementing-pathfinding-for-ai-agents-with-navmesh-in-unity-r4903/

The pathfinding library itself (this one, at least ...) does not consider things like agent size or height, so that would need to be built into the navmesh.

FrameMuse commented 4 months ago

@donmccurdy But what if I have many different unit types that have different sizes? I don't think a good way is to create nav mashes for all unit types. I would like it to be a property that can be changed easily in code and dynamically.

donmccurdy commented 4 months ago

I could certainly be wrong, but I believe this is generally how navmeshes work. Consider larger margins – if you have larger characters that cannot fit through narrower spaces, you would generate different navmeshes for them, and their paths may be very different from smaller characters' paths. Navmeshes can be regenerated dynamically, too. The tradeoff is so that pathfinding (which might run as often as every frame) can be as cheap as possible.