Skip to content
/ yuka Public

NavMesh.getClosestRegion a better approach? #20

@Glidias

Description

@Glidias

The getClosestRegion is rather moot since it uses a naive distance to centroid which isn't very accruate. It should calculate it based on whether the point lies within the region bounds (in 2D), and if so, maybe use a distance to plane as a metric (or maybe downward ray distance to plane?). If it doesn't lie within region bounds, then check distance to closest edge on polygon.

It could also consider (maybe given an allowance setting?), the CellSpacePartioninig (if available), to speed up the query and zero in on cells that lie within the allowance setting from the point. Currently, this is only supported for getRegionForPoint(pt) method. For the case of querying multiple cells, visited polygons ma be marked as "dirty" for the given timestamp ID query. eg.

// for each query
timestamp++;
// .....
if (polygon.__myNavTimeStamp !== timestamp) {
   polygon.__myNavTimeStamp  = timestamp;
    // process polygon
 }

to avoid visiting polygon twice. (or maybe a Set to check for visited polygons).

Why not use something like getClosestRegion( point , allowance?, resultPt?) ....which can optionally get the resultPt that is clamped closest to the navmesh region. Also, during findPath(), in the event the start point lies OUTSIDE the navmesh, a dummy prior starting straight line route leading from current position to the clamped start position (closest to start) can be done.

I'd probably do up this feature later if/when I need it though.

CellSpacePartioning may also work quite well with a raycast, (probably an optional seperate utility), using a step-based DDA routine to only capture cells along the ray path, prefably with a max distance limit.

As of now, I must ensure that the input points given to the function always lie within the navmesh for optimal results.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions