Godot Version
Godot4.6
Question
I am currenty trying to generate voxel terrain. I want to smooth out the steps between blocks by generating half-blocks. Right now, I am generating half-blocks by using if frac.. , however failing to achieve the result i am aiming for.
How can I:
- Generate half-blocks only in a single line at the step edges, rather than forming full surfaces?
- Prevent half-blocks from being generated on the top and bottom surfaces of the terrain?
I would greatly appreciate any advice or suggestions. Thank you in advance.
func terrain_generation():
init_height_map()
generate_height_map()
for x in SIZE:
for z in SIZE:
var height = height_map[x][z]
var base_h = int(floor(height))
var frac = height - base_h
base_h = clamp(base_h, 0, HEIGHT - 1)
for y in HEIGHT:
if y > base_h:
if y <= SEA_LEVEL:
blocks[x][y][z] = 4
else:
blocks[x][y][z] = 0
elif y == base_h: # 地表
if height < SEA_LEVEL:
blocks[x][y][z] = 3
else:
blocks[x][y][z] = 1
elif y > base_h - 3:
if height < SEA_LEVEL:
blocks[x][y][z] = 3
else:
blocks[x][y][z] = 2
else:
blocks[x][y][z] = 3
if frac > 0.75: #Generate Half-Block
if base_h + 1 < HEIGHT:
if height >= SEA_LEVEL:
blocks[x][base_h + 1][z] = 5
