The AStar class implements the pathfinding algorithm using the classes we have implemented so far. If you want a quick review of the A* algorithm, see the Revisiting the A* algorithm section from earlier in this chapter. The steps for implementation of AStar are as follows:
- We start with our openList declaration, which is a PriorityQueue type variable, and closedList, which is a HashSet of nodes. The AStar.cs file is as follows:
using UnityEngine;using System.Collections;using System.Collections.Generic; public class AStar { public static PriorityQueue openList; public static HashSet<Node> closedList;
- We implement a method called HeuristicEstimateCost to calculate the cost between the two nodes. The calculation is simple. ...