private Vector3[] GetFaceVertices(int direction, Vector3i position) { Vector3[] result = new Vector3[4]; for (int i = 0; i < 4; i++) { result [i] = position.Add(cube.CubeVertices[cube.CubeIndices[direction][i]]); } return(result); }
//update colliders of certain chunk (array units) private void UpdateColliders(int x, int z) { if (this.chunks [x, z] != null) { List <Vector3i> colliderVoxels = this.chunks[x, z].GetComponent <Chunk>().GetColliderVoxels(playerTransform.position, this.colliderDistance); Vector3i chunkWorldPosition = this.chunks[x, z].GetComponent <Chunk>().worldPosition; for (int i = 0; i < colliderVoxels.Count; i++) { Vector3i blockPosition = colliderVoxels[i]; Vector3i worldPosition = blockPosition.Add(chunkWorldPosition); GameObject newCollider = new GameObject(); this.blockColliders.Add(newCollider); newCollider.name = (x.ToString() + "_" + z.ToString() + "_" + i.ToString()); newCollider.AddComponent <BoxCollider>(); newCollider.transform.position = new Vector3(worldPosition.x, worldPosition.y, worldPosition.z); newCollider.transform.SetParent(this.terrainCollider.transform); } } }
//returns true if block has a neighbor public bool HasNeighbor(Vector3i position, Vector3i direction) { bool result = false; Vector3i requestedBlock = position.Add(direction); if (requestedBlock.x < 0 || requestedBlock.x >= this.size || requestedBlock.y < 0 || requestedBlock.y >= this.size || requestedBlock.z < 0 || requestedBlock.z >= this.size) { return(false); } byte blockType = this.blocks [requestedBlock.x, requestedBlock.y, requestedBlock.z].type; if (!this.blockDatabase.blockMaterials[blockType].transparent) { result = true; } return(result); }