Skip to content

Commit 2aee803

Browse files
committed
Made variables constant and fixed terrain stretching issue
1 parent 88ecdf2 commit 2aee803

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Assets/Voxels/Scripts/Chunk.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class Chunk
1313
public static ConcurrentDictionary<Vector3Int, Chunk> chunks = new ConcurrentDictionary<Vector3Int, Chunk>();
1414
public static HashSet<Chunk> dirtyChunks = new ();
1515

16-
public static readonly byte CHUNK_WIDTH = (byte)(16 / Generation.BLOCK_SIZE);
17-
public static readonly byte CHUNK_LENGTH = (byte)(16 / Generation.BLOCK_SIZE);
18-
public static readonly byte CHUNK_HEIGHT = (byte)(16 / Generation.BLOCK_SIZE);
16+
public const byte CHUNK_WIDTH = 64;
17+
public const byte CHUNK_LENGTH = 64;
18+
public const byte CHUNK_HEIGHT = 64;
1919

2020
public enum Direction { RIGHT = 0, LEFT = 1, FORWARD = 2, BACK = 3, UP = 4, DOWN = 5}
2121
public static readonly Direction chunkDirection;
@@ -156,7 +156,11 @@ public void SetBlockArray()
156156

157157
for (int y = 0; y < CHUNK_HEIGHT; y++)
158158
{
159-
float yCoord = (y * blockSize) + chunkPos.y;
159+
// Our chunk position assumes are blocks are 1 by one (by default our blocks are 1/4th the size of a normal block
160+
// So our 64 by 64 chunk of 1/4 sized voxels is equal to a 16 by 16 sized chunks of 1 by 1 voxel.
161+
// We divide by blockSize (0.25) to find the actual y position of the voxel
162+
float yCoord = y + (chunkPos.y / blockSize);
163+
160164
if (yCoord > yVal) { break; }
161165

162166
if (slope > 1f)

Assets/Voxels/Scripts/Generation.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class Generation : MonoBehaviour
88
[SerializeField] string inputSeed;
99
[HideInInspector] public long seed;
1010

11-
public static readonly float BLOCK_SIZE = 0.25f;
12-
public static readonly int WORLD_HEIGHT = 1024;
11+
public const float BLOCK_SIZE = 0.25f;
12+
public const int WORLD_HEIGHT = 1024;
1313
private int subChunks;
1414

1515

@@ -74,7 +74,6 @@ private IEnumerator InititalizeChunks()
7474
// i / 16 gives you the y coordinate, which increases every 16 steps and % subChunks resets to 0 when it completes a cycle.
7575
int x = i % 16;
7676
int y = (i / 16) % subChunks;
77-
7877
int z = i / (16 * subChunks);
7978

8079
chunkPos.x = x;

0 commit comments

Comments
 (0)