Skip to main content

Pathfinder

The pathfinder class manages basic pathfinding logic based on an implementation of the A* algorithm and a custom MinHeap data structure.

This class uses the pathfinding property of the CellData base class to determine movement cost and whether a cell is an obstacle.

caution

Pathfinding currently works in most cases. However, it is still work in progress and might deliver suboptimal paths in specific cases. Please don't expect A* project level pathfinding. Improving pathfinding is high up on the current roadmap

Public methods

GetPath

public List<Vector3Int> GetPath(Vector3Int start, Vector3Int destination)

Returns a list of grid positions forming the shortest path between the start and destination points. Returns an empty list if the destination is not passable or doesn't contain cell data.

Parameters

  • start: The starting point from which to start the path.
  • destination: The destination point of the path.

Example

var playerPosition = new Vector3Int(0, 0, 0);
var target = new Vector3Int(5, 2, 0);
//Creates a shortest path between the player and the target
var path = tilemapExtended.Pathfinder.GetPath(playerPosition, target);

foreach (var point in path) {
//Do something with path
}