Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a tree model touch right above the smooth terrain?

Asked by 7 years ago
local Seed = 500 -- The answer to life, the universe and everything.
local m = Instance.new("Model", game.Workspace)
m.Name = "Terrain"

for X = 0,200 do -- X Loop

    for Z = 0,200 do -- Z Loop
        local nn = 0
        -- Make the part
        local p = Instance.new("Part",m) 
        p.Anchored = true
        p.Size = Vector3.new(5,5,5)

        --Just for style
        p.TopSurface = "Smooth"
        p.Material = Enum.Material.Grass
        p.BrickColor = BrickColor.Green()
        p.Transparency = 1
        p.CanCollide = false

        --The noise
        Y = math.noise(X/20,Z/20,Seed) * 5

        --Set the position
        p.CFrame = CFrame.new(X*5,Y*10,Z*5)
        if Y < 1 then
            game.Workspace.Terrain:FillBlock(p.CFrame, p.Size, Enum.Material.LeafyGrass)
        elseif Y > 1 and Y < 1.8 then
            game.Workspace.Terrain:FillBlock(p.CFrame, p.Size, Enum.Material.Ground)
        else if Y >= 1.3 then
            game.Workspace.Terrain:FillBlock(p.CFrame, p.Size, Enum.Material.Rock)
        end
    end
        print(Y)
    end
    --Wait a bit so your toaster doesn't freeze.
    wait()
end
--Tfw you write all of this and it works in one try.
wait(5)
for i = 0,200 do -- Generate Trees
    local tree = game.ReplicatedStorage.bigOakTree:Clone()
    tree.Parent = game.Workspace
    tree:TranslateBy(Vector3.new(math.random(1,800), Y , math.random(50,800)))
end
print("------------------------------------")
print("Done")

Link to generator is here. See for yourself. https://www.roblox.com/games/748303482/Terrain-Generation-For-The-Trial

Answer this question