Direct 2D and 3D paths: query and validate
Obtain points and distinguish complete from projected routes.
NavigationServer2D.MapGetPath returns Vector2[]; NavigationServer3D.MapGetPath returns Vector3[]. Direct queries do not require a NavigationAgent, but need a live map with published navigation geometry.
Obtain points
Supply the intended map RID, start and target in map-global coordinates, processing mode and layer mask. An existing region provides its map through GetNavigationMap(). For a standard world, use GetWorld2D().NavigationMap or GetWorld3D().NavigationMap inside an appropriate Entity in the tree.
Save SimplePaths.cs in a Reckfell 1.0.0 C# project:
using Reckfell;
using System;
public static class SimplePaths
{
public static Vector2[] Find2D(Rid map, Vector2 start, Vector2 target,
uint layers = 1, bool optimize = true)
{
if (!map.IsValid || layers == 0 || NavigationServer2D.MapGetIterationId(map) == 0)
return Array.Empty<Vector2>();
return NavigationServer2D.MapGetPath(map, start, target, optimize, layers);
}
public static Vector3[] Find3D(Rid map, Vector3 start, Vector3 target,
uint layers = 1, bool optimize = true)
{
if (!map.IsValid || layers == 0 || NavigationServer3D.MapGetIterationId(map) == 0)
return Array.Empty<Vector3>();
return NavigationServer3D.MapGetPath(map, start, target, optimize, layers);
}
}Call Find2D or Find3D with a RID of the matching dimension. The helper returns an empty array for a zero RID, mask zero or an unpublished map. It cannot detect whether a nonzero RID was already freed: the caller must manage map lifetime.
On the checked x=0–10 surface, the path from (1, 5) to (9, 5) ends at (9, 5). Adding a touching x=10–20 region to the same map makes (19, 5) accessible. The same region on another map does not participate.
Validate the result
- Do not access
path[0]when the array is empty. Check geometry, map, mask and synchronization. - Compare the first point with the requested start: a start outside allowed geometry can be projected.
- Compare the last point with the target using your game tolerance. An unreachable target can produce a partial route rather than an empty array.
- Accept partial routes only as an explicit gameplay decision. Existing points do not establish that the target was reached.
See query objects for a complete helper checking both endpoints. A navigation link can cross empty space: path points do not promise a continuous physical floor. Such segments need transition logic.
What optimize changes
true corresponds to Corridorfunnel, shortening the path inside the found polygon corridor. false corresponds to Edgecentered, placing intermediate points at crossed-edge centers. It neither disables A* nor promises a faster query. Both mappings were checked against QueryPath on the same map.
Choose QueryPath for metadata, region filters, clipping and repeated parameter-object reuse. Avoid searching every frame without a reason: decide when targets, maps or route conditions change, and measure your game workload.
Follow the route
Retain the current point index. Advance when the character approaches within a chosen tolerance, and finish after the last point. For a physics character, use its body movement API rather than overwriting position directly: see first 3D character.
A path array does not update itself after map changes, move an Entity or implement avoidance. Request a new route separately. The game must also handle stuck characters and unreachable targets.
Executed checks cover exact 2D/3D helpers, complete and projected output, map isolation, a zero mask and matching 2D processing modes. Physical path following, complex meshes, performance and optimization quality were not tested by this suite.