Its been a while i’m trying to make a procedural planet (as sphere) generator. After a few days, i managed to came up with a working sphere planet generator (thanks to other posts on the devforum). However i really don’t know how i could implement a tree positioning system. I already tried but got no luck. Here is the code, hope it can help!
local steps = 0
local layer = 0
local origin = workspace.PlanetCenter.Position
local diameter = 1500
local segmentSize = Vector3.new(30, 30, 10)
local seed = math.random(0,10e6)
local noiseScale = 1/math.random(150, 250)
local amplitude = math.random(40, 130)
local meshDirectory = game.ReplicatedStorage.PlanetAssets
function getMaterial(height)
if height <= 50 then
if math.random(1,math.random(6,15)) == 3 then
return Enum.Material.Rock
else
return Enum.Material.Grass
end
elseif height >= 100 then
return Enum.Material.Rock
end
if math.random(1,math.random(4,10)) == 1 then
return Enum.Material.Rock
else
return Enum.Material.Snow
end
end
local radius = diameter / 2
repeat
repeat
local position = CFrame.Angles(math.rad(steps), math.rad(-layer), math.rad(0)) * CFrame.new(0, 0, math.abs(radius))
local cx, cy, cz = position.Position.x, position.Position.y, position.Position.z
local noise = math.noise(cx * noiseScale, cy * noiseScale, cz * noiseScale, seed) * amplitude
local newRadius = radius + noise
local newPos = CFrame.Angles(math.rad(steps), math.rad(-layer), math.rad(0)) * CFrame.new(0, 0, math.abs(newRadius))
workspace.Terrain:FillBlock(newPos + origin, segmentSize, getMaterial(noise))
steps = steps + 1
until steps == 360
steps = 0
layer = layer + 1
task.wait()
until layer == 90
print('done 1')
steps = 0
layer = 0
repeat
repeat
local position = CFrame.Angles(math.rad(steps), math.rad(-layer), math.rad(0)) * CFrame.new(0, 0, math.abs(radius))
local cx, cy, cz = position.Position.x, position.Position.y, position.Position.z
local noise = math.noise(cx * noiseScale, cy * noiseScale, cz * noiseScale, seed) * amplitude
local newRadius = radius + noise
local newPos = CFrame.Angles(math.rad(steps), math.rad(-layer), math.rad(0)) * CFrame.new(0, 0, math.abs(newRadius))
workspace.Terrain:FillBlock(newPos + origin, segmentSize, getMaterial(noise))
steps = steps + 1
until steps == 360
steps = 0
layer = layer - 1
task.wait()
until layer == -90
print('done 2')
Thanks, gianfragolo