I’m currently trying to make procedural terrain generation using the Terrain:WriteVoxels() function.
Everything is almost 100% perfect except for the terrain smoothing. I just can’t figure out how to make it look normal. Here is what it looks like:
I’ve tried messing around with my math function a little bit (no surprise it didn’t work) so I’m basically just looking for help with that.
This is the code for determining the occupancy. VOXEL_SIZE is 4 and gridHeight is just a y-value aligned to multiples of 4
local averageHeight = (
getHeightFromPosition(x - 0.5, z - 0.5, config) +
getHeightFromPosition(x - 3.5, z - 0.5, config) +
getHeightFromPosition(x - 0.5, z - 3.5, config) +
getHeightFromPosition(x - 3.5, z - 3.5, config)
) / 4
local gridHeight = math.ceil(averageHeight / VOXEL_SIZE) * VOXEL_SIZE
local occupancy = (gridHeight - averageHeight) / VOXEL_SIZE
local mappedX = (x - chunkX + 4) / 4
local mappedZ = (z - chunkZ + 4) / 4
local position = Vector3.new(mappedX, gridHeight/4, mappedZ)
local material = getMaterialFromPosition(position, config)
if gridHeight > height then
height = gridHeight
end
mapData[position] = {
Occupancy = occupancy,
Material = material
}
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.