AstarAgent#

class in UltimateIsometricToolkit.Scripts.Pathfinding / Inherits from MonoBehaviour

Description#

AstarAgent allows to move on a path using the Astar algorithm

Seealso

(Astar,GridGraph)

Variables#

Type Name Description
float JumpHeight Maximum allowed vertical distance to travel between a pair of nodes in unity units
float Speed Movement speed in units per second
GridGraph Graph Graph to execute Astar on
Heuristic Heurstic Chosen heuristic for this AstarAgent

Public functions#


void MoveTo(Vector3 destination)#

Moves the character to the closest node to destination in a coroutine.

Warning

This will also stop any other coroutine running on that object. This function should therefore not be called per frame (e.g. Update(), LateUpdate, etc.) but rather on specific events like touch/mouse inputs

1
2
3
4
  void Update() {
    var destination = IsoTransform.Position + Vector3.forward * 2;
    MoveTo(destination); // will invoke pathfinding and immediately stop the coroutine in the next frame
  }

Failure

1
2
3
4
5
  void Update() {
    //moves closest to 10,1,10 on left mouse button down
    if(Input.GetMouseDown(0))
      MoveTo(new Vector3(10,1,10));
    }

Success