Tidy Tile Mapper‎ > ‎Runtime API‎ > ‎BlockUtilities‎ > ‎

GetPath

Returns a path between the given coordinates over the targetted BlockMap.
This is calculated using the A* algorithm, and only applies over a 2D slice of the BlockMap.
That is to say, it will not path between depths.

Note: The GetPath function returns the collection of points from the target, to the target (if there is a path) excluding the ending point.

(Editor's Note: I'm sure there was a reason for this. But this, like a lot of things, has been lost to the ages)

The recommended style of pathing function is as follows (this is taken from the PathingEntity.cs template that comes with the tool).

public void PathTo(int x, int y, int z){
	
	currentPath.Clear();
	
	currentPath = BlockUtilities.GetPath(parentMap,this.x,this.y,(int)x,(int)y,z,false);
	
	if(currentPath == null || currentPath.Count <= 0){
		currentPath = new List<Vector3>();
	}
	else{
		currentPath.Add(new Vector3(x,y,z));
	}
	
	SetIsIdle(true);
}

So as you can see, we add the destination point to the path if the path returns and is not null.

To decide if a node can be pathed through - the function checks the following (function IsWalkable in the BlockMap class):

if(b != null && !b.isNullBlock && !b.actAsEmptyBlock && !pathOverAllBlocks)

Is the Block a null block (i.e an empty block)?
Is the Block acting as an Empty Block (i.e act empty is ticked)?
Has the pathing funciton been asked to path over all Blocks?

If any of these are true, the pathing function will path through this block.

Definition:

List<Vector3> GetPath(BlockMap map, int from_x, int from_y, int to_x, int to_y, int depth, bool useDiagonals)

Return value Description
List<Vector3> A list of coordinates corresponding to path-able map positions. Empty if no path was available. Truncated if the pathing timed-out for some reason.

Argument DataType Description
map BlockMap The BlockMap through which you wish to find a path.
from_x int The x coordinate at which you wish your path to begin.
from_y    int The y coordinate at which you wish your path to begin.
to_x int The x coordinate to which you wish your path to go.
to_y int The y coordinate to which you wish your path to go.
depth int The depth (z) value of slice through which you wish to path.
useDiagonals bool Use diagonals on our path, or path in only up, down, left and right directions?

Comments