Weird terrain occupancy behavior

I am trying to write a noise-based terrain generator on Roblox. In my current tests, I am only trying to change the occupancies of voxels at the surface. I used a for loop like so to randomize these occupancies:

local chunks = create(FOURTH_CHUNK_SIZE, create(FOURTH_TERRAIN_HEIGHT, create(FOURTH_CHUNK_SIZE, 0.05)))

for i = 1, FOURTH_CHUNK_SIZE * FOURTH_CHUNK_SIZE do
	chunks[math.ceil(i / FOURTH_CHUNK_SIZE)][FOURTH_TERRAIN_HEIGHT][i % FOURTH_CHUNK_SIZE + 1] = math.random()
end

(Note: I did originally use two loops, but I found that their behavior can be quite strange. They had the same problem as this snippet.)

However, when I went to test the code, instead of the expected bumpy terrain, I got striations like this:


So I asked myself, “okay, what happens if I change the occupancy of a single voxel on the surface?”

So I did.

chunks[1][FOURTH_TERRAIN_HEIGHT][1] = 1

And this was the result:


This behavior is really strange. Does anyone know what’s going on or if I’m doing something wrong?

1 Like

Note: I have been able to replicate the behavior I wanted by using smaller chunks with these random striations. It isn’t perfect, but it is the best I could do.

Eiminates the use of the single loop and maintains indexing. Avoids having to deal with the i % FOURTH_CHUNK_SIZE

local chunks = create(FOURTH_CHUNK_SIZE, create(FOURTH_TERRAIN_HEIGHT, create(FOURTH_CHUNK_SIZE, 0.05)))

for z = 1, FOURTH_CHUNK_SIZE do
	for x = 1, FOURTH_CHUNK_SIZE do
		chunks[z][FOURTH_TERRAIN_HEIGHT][x] = math.random()
	end
end

Or once again I’m totally wrong. Been working with this stuff for a while.
But without testing … you can never really tell.