Diving into our A* implementation

The AStar class is the actual implementation of the A* algorithm. This is where the magic happens. The code in the AStar.cs file looks like this:

using UnityEngine;using System.Collections;public class AStar{    public static PriorityQueue closedList;    public static PriorityQueue openList;        private static ArrayList CalculatePath(Node node)    {        ArrayList list = new ArrayList();        while (node != null)        {            list.Add(node);            node = node.parent;        }        list.Reverse();        return list;    }        /// Calculate the estimated Heuristic cost to the goal     private static float EstimateHeuristicCost(Node curNode, Node goalNode)    {        Vector3 vecCost = curNode.position - goalNode.position;        return vecCost.magnitude;    }     // Find the path between start node ...

Get Unity 2017 Game AI Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.