I recently got back into game development and tried to make a blocky terrain generation. but I could not grasp how will I do this. I tried to do something like:
local heights = {10, 7, 5, 2}
local y = get_closest(heights, noiseValue)
but it comes out as a flat terrain? even thought the noiseValue were fine.
i deleted the script a few hours ago because it was too messy, but this should be the same:
local function get_closest(t, v)
local closest, closest_diff = nil, math.huge
for _, height in t do
local diff = math.abs(height-v)
if diff < closest_diff then
closest_diff = diff
closest = height
end
end
return closest
end