Skip to content

Commit

Permalink
FIX using static neighbors array, just updating the values
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomikoski committed Mar 11, 2018
1 parent f2c6cb6 commit 98646c0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Assets/[Pathfinding]/Scripts/Pathfinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class Pathfinder
private static List<Tile> openList = new List<Tile>();
private static Dictionary<int, Tile> tileIndexToTileObjectOpen = new Dictionary<int, Tile>();
private static HashSet<Tile> closedList = new HashSet<Tile>();
private static Tile[] neighbors = new Tile[4];

public static void Initialize( GridController targetGridController )
{
Expand Down Expand Up @@ -56,9 +57,9 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
if ( currentTile == destinationTile )
break;

Tile[] neighbours = GetPathTileNeighbors( currentTile );
UpdateNeighbors( currentTile );

foreach ( Tile neighbourPathTile in neighbours )
foreach ( Tile neighbourPathTile in neighbors )
{
if ( neighbourPathTile == null )
continue;
Expand Down Expand Up @@ -104,9 +105,8 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile )
(targetFromTile.TilePosition.y - targetToTile.TilePosition.y);
}

private static Tile[] GetPathTileNeighbors( Tile targetTile )
private static Tile[] UpdateNeighbors( Tile targetTile )
{
Tile[] neighbors = new Tile[4];
neighbors[0] = GetNeighborAtDirection( targetTile, NeighborDirection.LEFT );
neighbors[1] = GetNeighborAtDirection( targetTile, NeighborDirection.TOP );
neighbors[2] = GetNeighborAtDirection( targetTile, NeighborDirection.RIGHT );
Expand Down

0 comments on commit 98646c0

Please sign in to comment.