public ScrTile[] GetNeighbors(int xGridCoord, int yGridCoord) { List <ScrTile> neighbors = new List <ScrTile>(); ScrTile tempTile = null; if (xGridCoord + 1 < gridWidth) { tempTile = dungeonTileGrid[xGridCoord + 1, yGridCoord]; if (tempTile != null) { if (tempTile.tag != "Blocked Tile") { neighbors.Add(tempTile); } } } if (xGridCoord - 1 > -1) { tempTile = dungeonTileGrid[xGridCoord - 1, yGridCoord]; if (tempTile != null) { if (tempTile.tag != "Blocked Tile") { neighbors.Add(tempTile); } } } if (yGridCoord + 1 < gridHeight) { tempTile = dungeonTileGrid[xGridCoord, yGridCoord + 1]; if (tempTile != null) { if (tempTile.tag != "Blocked Tile") { neighbors.Add(tempTile); } } } if (yGridCoord - 1 > -1) { tempTile = dungeonTileGrid[xGridCoord, yGridCoord - 1]; if (tempTile != null) { if (tempTile.tag != "Blocked Tile") { neighbors.Add(tempTile); } } } return(neighbors.ToArray()); }
private void GoToNextTile() { ScrTile[] neighbors = nextTile.GetNeighbors(); foreach (ScrTile tile in neighbors) { if (tile.name == "Boss Tile") { nextTile = tile; agent.SetDestination(nextTile.transform.position); return; } } nextTile = GetRandomNeighborWeighted(neighbors); agent.SetDestination(nextTile.transform.position); }
private ScrTile GetRandomNeighborWeighted(ScrTile[] _neighbors) { float frontWeight = 55.0f; float sideWeight = 30.0f; float backWeight = 15.0f; do { ScrTile randomNeighbor = _neighbors[Random.Range(0, _neighbors.Length)]; float randomValue = Random.Range(0.0f, 100.0f); int randNeighborGridX = randomNeighbor.gridCoord[0]; if (randNeighborGridX < nextTile.gridCoord[0]) //Check if neighbor is in front { if (randomValue <= frontWeight) { return(randomNeighbor); } } if (randNeighborGridX == nextTile.gridCoord[0]) //Check if neighbor is on side { if (randomValue <= sideWeight) { return(randomNeighbor); } } if (randNeighborGridX > nextTile.gridCoord[0]) //Check if neighbor is in back { if (randomValue <= backWeight) { return(randomNeighbor); } } } while (true); }
public void InitializeHamster(ScrTile _destinationTile) { nextTile = _destinationTile; agent = GetComponent <NavMeshAgent>(); agent.SetDestination(nextTile.transform.position); }