To make the floating island have fast erosion at the edges and slower, more gradual changes at the center (quadratic the "other way"), we need to invert the falloff function. Instead of using falloff = 1 - (distance/radius)^2, we'll use a Gaussian-like falloff or a higher-order polynomial that decays quickly near the edges but stays flatter in the center.
Here's the updated version of the generate_floating_island function with fast edge falloff and slow center variation, using a Gaussian-inspired quadratic falloff:
local function generate_floating_island(player_name, params)
local player = minetest.get_player_by_name(player_name)
if not player then
return false, "Player not found"
end
-- Default configuration
local config = {
radius = tonumber(params.radius) or 15,
height_above = tonumber(params.height_above) or 20,
max_height = tonumber(params.max_height) or 8,
max_depth = tonumber(params.max_depth) or 6,
noise_scale = tonumber(params.noise_scale) or 0.3,
edge_sharpness = tonumber(params.edge_sharpness) or 3.0, -- Higher = sharper edges, flatter center
layers = params.layers or {
{name = "default:dirt_with_grass", thickness = 1},
{name = "default:dirt", thickness = 3},
{name = "default:stone", thickness = -1}
}
}
local player_pos = player:get_pos()
local center_pos = {
x = math.floor(player_pos.x),
y = math.floor(player_pos.y + config.height_above),
z = math.floor(player_pos.z)
}
-- Noise for terrain variation
local noise_params = {
offset = 0,
scale = 1,
spread = {x = config.radius * 2, y = config.radius * 2, z = config.radius * 2},
seed = math.random(1, 10000),
octaves = 3,
persistence = 0.5,
lacunarity = 2.0,
}
local perlin = minetest.get_perlin(noise_params)
local positions_to_update = {}
for x = -config.radius, config.radius do
for z = -config.radius, config.radius do
local distance = math.sqrt(x * x + z * z)
if distance <= config.radius then
-- === NEW: FAST EDGE FALLOFF (Gaussian-like quadratic) ===
-- This creates: FLAT center, SHARP drop at edges
-- falloff = exp(-(d/r)^n) where n > 2 gives sharp edges
local normalized_distance = distance / config.radius
local falloff = math.exp(-math.pow(normalized_distance * config.edge_sharpness, 2))
-- Optional: Add a small flat center region (optional tweak)
-- local flat_core = 0.1 -- 10% center is perfectly flat
-- if normalized_distance < flat_core then
-- falloff = 1.0
-- else
-- falloff = math.exp(-math.pow((normalized_distance - flat_core) / (1 - flat_core) * config.edge_sharpness, 2))
-- end
-- Get noise for organic variation
local noise_2d = perlin:get_2d({x = center_pos.x + x, y = center_pos.z + z})
-- Apply falloff to height and depth
local terrain_height = math.floor(
config.max_height * falloff * (1 + noise_2d * config.noise_scale)
)
local terrain_depth = math.floor(
config.max_depth * falloff * (1 + math.abs(noise_2d) * config.noise_scale * 0.7)
)
-- Ensure minimum thickness (avoid disappearing at edges)
terrain_height = math.max(terrain_height, 1)
terrain_depth = math.max(terrain_depth, 1)
-- Generate column
local current_y = center_pos.y + terrain_height
local bottom_y = center_pos.y - terrain_depth
for y = current_y, bottom_y, -1 do
local depth_from_top = current_y - y
local node_name = nil
local accumulated = 0
for _, layer in ipairs(config.layers) do
if layer.thickness == -1 then
node_name = layer.name
break
else
accumulated = accumulated + layer.thickness
if depth_from_top < accumulated then
node_name = layer.name
break
end
end
end
if node_name then
local pos = {x = center_pos.x + x, y = y, z = center_pos.z + z}
minetest.set_node(pos, {name = node_name})
table.insert(positions_to_update, pos)
end
end
-- Vegetation only on top, with higher chance in center
if terrain_height > 0 and math.random() < 0.15 * falloff then
local top_pos = {
x = center_pos.x + x,
y = center_pos.y + terrain_height + 1,
z = center_pos.z + z
}
local vegetation = {
"default:grass_1","default:grass_2","default:grass_3",
"default:grass_4","default:grass_5",
"flowers:rose","flowers:tulip","flowers:dandelion_yellow"
}
if minetest.registered_nodes[vegetation[1]] then
minetest.set_node(top_pos, {name = vegetation[math.random(#vegetation)]})
end
end
end
end
end
return true, "Floating island with sharp-edge falloff generated!"
end
🔧 Key Change: falloff = exp(-(d/r * sharpness)^2)
edge_sharpness parameter (default: 3.0)
- Higher values (e.g., 4–6): Very sharp edges, island looks like a plateau with steep sides
- Lower values (e.g., 1–2): Gradual slopes, more natural dome
- Gaussian falloff ensures:
- ✅ Center is flat and wide (slow change)
- ✅ Edges drop off rapidly (fast change)
- ✅ No abrupt cliffs unless you want them (tune
edge_sharpness)
📈 Visual Comparison:
| Falloff Type | Center | Edges | Use Case |
|---|
1 - (d/r)² | Rounded | Smooth | Natural islands |
exp(-d²) (this) | Flat | Sharp | Floating plateaus, sky cities |
exp(-d⁴) | Very flat | Very sharp | Artificial floating platforms |
🛠️ Updated Chat Commands (with edge_sharpness):
Update the island and island_custom commands to include the new parameter:
-- In the basic /island command:
params.edge_sharpness = tonumber(args[6]) or 3.0
-- In /island_custom:
params.edge_sharpness = tonumber(args[6]) or 3.0
-- Then layers start at args[7]...
-- Example usage:
/island 20 30 10 8 0.35 4.5
-- Creates a 20-block radius island, 30 blocks up, max 10 high, 8 deep,
-- noise scale 0.35, and very sharp edges (4.5 sharpness)
/island_custom 25 40 12 10 0.4 5.0 default:dirt_with_grass:1 default:dirt:5
-- Custom layers with ultra-sharp edges
🎯 Result:
You now get floating islands that look like sky plateaus — wide, flat centers with dramatic, steep edges, perfect for:
- Floating castles
- Sky villages
- Nether-style obsidian islands
- Magical floating landmasses
The terrain variation is still present in the center (thanks to noise), but the overall shape is flat and stable, with fast erosion at the borders for a dramatic visual effect. 🌤️🏔️