public void AStar(Vector2 startPos, Vector2 endPos, List <Vector2> grid, bool includeDiagonals = true, bool checkForWalls = false) { Dictionary <Vector2, AStarNode> allNodes = new Dictionary <Vector2, AStarNode> (); Vector2 start = startPos; Vector2 end = endPos; float shortestStartDistance = 100; float shortestEndDistance = 100; // Turn provided vector2 into spots on the grid foreach (var item in grid) { AStarVector v = new AStarVector(item); allNodes.Add(item, new AStarNode(v, checkForWalls)); float sdistance = Vector2.Distance(startPos, item); float edistance = Vector2.Distance(endPos, item); if (shortestStartDistance > sdistance) { shortestStartDistance = sdistance; start = item; } if (shortestEndDistance > edistance) { shortestEndDistance = edistance; end = item; } } StartCoroutine(AStarAlgorithm(includeDiagonals, allNodes, start, end)); }
public AStarNode(AStarVector weightedVector, bool wallBlock) { this.pos = weightedVector.pos; this.w = weightedVector.weight; this.wallBlock = wallBlock; // this.f = f; // this.g = g; // this.g = h; }