VoxelAStarGrid3D
Grid-based A* pathfinding algorithm adapted to blocky voxel terrain.
Grid-based A* pathfinding algorithm adapted to blocky voxel terrain.
This can be used to find paths between two voxel positions on blocky terrain. It is tuned for agents 2 voxels tall and 1 voxel wide, which must stand on solid voxels and can jump 1 voxel high. No navmesh is required, it uses voxels directly with no baking. However, search radius is limited by an area (50 voxels and above starts to be relatively expensive). At the moment, this pathfinder only considers voxels with ID 0 to be air, and the rest is considered solid. Note: "positions" in this class are expected to be in voxels. If your terrain is offset or if voxels are smaller or bigger than world units, you may have to convert coordinates.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
VoxelAStarGrid3DConstructor
public VoxelAStarGrid3D();Methods7
DebugGetVisitedPositionsReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> DebugGetVisitedPositions();Gets the list of voxel positions that were visited by the last pathfinding request (relates to how A* works under the hood). This is for debugging.
Reckfell.Collections.Array<Vector3I>FindPathReckfell.Collections.Array<Vector3I>
public Reckfell.Collections.Array<Vector3I> FindPath(Vector3I fromPosition, Vector3I toPosition);Calculates a path starting from a voxel position to a target voxel position.
Those positions should be air voxels just above ground with enough room for agents to fit in.
The returned path will be a series of contiguous voxel positions to walk through in order to get to the destination.
If no path is found, or if either start or destination position is outside of the search area, an empty array will be returned.
You may also use VoxelAStarGrid3D.SetRegion to specify the search area.
| Name | Type | Default |
|---|---|---|
fromPosition | Vector3I | — |
toPosition | Vector3I | — |
Reckfell.Collections.Array<Vector3I>FindPathAsyncvoid
public void FindPathAsync(Vector3I fromPosition, Vector3I toPosition);Same as VoxelAStarGrid3D.FindPath, but performs the calculation on a separate thread. The result will be emitted with the VoxelAStarGrid3D.AsyncSearchCompleted signal.
Only one asynchronous search can be active at a given time. Use VoxelAStarGrid3D.IsRunningAsync to check this.
| Name | Type | Default |
|---|---|---|
fromPosition | Vector3I | — |
toPosition | Vector3I | — |
GetRegionAabb
public Aabb GetRegion();Gets the maximum region limit that will be considered for pathfinding, in voxels.
AabbIsRunningAsyncbool
public bool IsRunningAsync();Returns true if a path is currently being calculated asynchronously. See VoxelAStarGrid3D.FindPathAsync.
boolSetRegionvoid
public void SetRegion(Aabb box);Sets the maximum region limit that will be considered for pathfinding, in voxels. You should usually set this before calling VoxelAStarGrid3D.FindPath.
The larger the region, the more expensive the search can get. Keep in mind voxel volumes scale cubically, so don't use this on large areas (for example 50 voxels is quite big).
| Name | Type | Default |
|---|---|---|
box | Aabb | — |
SetTerrainvoid
public void SetTerrain(VoxelTerrain terrain);Sets the terrain that will be used to do searches in.
| Name | Type | Default |
|---|---|---|
terrain | VoxelTerrain | — |
Signals and events1
AsyncSearchCompletedEvent
public event VoxelAStarGrid3D.AsyncSearchCompletedEventHandler AsyncSearchCompleted;Emitted when searches triggered with VoxelAStarGrid3D.FindPathAsync are complete.
| Name | Type | Default |
|---|---|---|
path | Reckfell.Collections.Array<Vector3I> | — |