public void CreateGrid() { grid = new SCR_Node[gridSizeX, gridSizeY]; Vector3 worldBottomLeft = transform.position - Vector3.right * gridSize.x / 2 - Vector3.up * gridSize.y / 2; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.up * (y * nodeDiameter + nodeRadius); bool walkable = !(Physics.CheckSphere(worldPoint, nodeRadius, unwalkableMask)); grid[x, y] = new SCR_Node(walkable, worldPoint, x, y); } } }
public void CreateGrid() { grid = new SCR_Node[gridSizeX, gridSizeY]; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 nodePosition = transform.position + Vector3.right * (x * nodeDiameter) + Vector3.forward * (y * nodeDiameter); bool walkable = !(Physics.CheckSphere(nodePosition, nodeRadius - 0.1f, unwalkableMask)); bool passable = false; if (walkable) { TILE_TYPE tempTile = new TILE_TYPE(); //Debug.Log(nodePosition +"Walkable "+ walkable); if (Physics.Raycast(nodePosition + Vector3.up, Vector3.down, out hitter, 5, typeMask)) { passable = true; //Debug.Log(hitter.transform.name); if (hitter.collider.CompareTag("Floor")) { tempTile = TILE_TYPE.FLOOR; } else if (hitter.collider.CompareTag("Stairs")) { tempTile = TILE_TYPE.STAIRS; } else if (hitter.collider.CompareTag("Highground")) { tempTile = TILE_TYPE.HIGHGROUND; } else if (hitter.collider.CompareTag("Hideout")) { tempTile = TILE_TYPE.HIDEOUT; } else if (hitter.collider.CompareTag("Buff")) { tempTile = TILE_TYPE.BUFF; } else if (hitter.collider.CompareTag("Debuff")) { tempTile = TILE_TYPE.DEBUFF; } //Debug.Log("NodePosition: " + nodePosition); grid[x, y] = new SCR_Node(walkable, passable, nodePosition, x, y, tempTile); } else { //Debug.Log("Not Hittin"); grid[x, y] = new SCR_Node(walkable, passable, nodePosition, x, y, TILE_TYPE.FLOOR); } } else { if (Physics.Raycast(nodePosition + Vector3.up, Vector3.down, out hitter, 5, unwalkableMask)) { if (hitter.collider.CompareTag("Player")) { passable = true; } } //Debug.Log("Walkable: " + walkable + "Passable: " + passable); grid[x, y] = new SCR_Node(walkable, passable, nodePosition, x, y, TILE_TYPE.OTHER); } } } }