private int GetDistance(NodePathfindingData data1, NodePathfindingData data2) { int deltaX = Mathf.Abs(data1.Node.X - data2.Node.X); int deltaY = Mathf.Abs(data1.Node.Y - data2.Node.Y); if (deltaX > deltaY) { return(_diagonalMoveDistance * deltaY + _moveDistance * (deltaX - deltaY)); } return(_diagonalMoveDistance * deltaX + _moveDistance * (deltaY - deltaX)); }
public Path(NodePathfindingData startNode, NodePathfindingData endNode) { Nodes = new List <Node>(); var currentNode = endNode; while (currentNode != startNode) { Nodes.Add(currentNode.Node); currentNode = currentNode.Parent; } Nodes.Reverse(); }
public AStarPathFinder(Grid grid) { _grid = grid; _nodes = new NodePathfindingData[_grid.Width, _grid.Height]; for (int i = 0; i < _grid.Width; i++) { for (int j = 0; j < _grid.Height; j++) { _nodes[i, j] = new NodePathfindingData(_grid.Nodes[i, j]); } } }