Skip to content

Instantly share code, notes, and snippets.

@B-Ricey763
Created August 14, 2025 14:07
Show Gist options
  • Select an option

  • Save B-Ricey763/4098b42a5dab6d7fb0dd1f0caa3a3aaf to your computer and use it in GitHub Desktop.

Select an option

Save B-Ricey763/4098b42a5dab6d7fb0dd1f0caa3a3aaf to your computer and use it in GitHub Desktop.
local ServerStorage = game:GetService("ServerStorage")
local tree = script.Parent
local root = tree.Root
local leafTemplate = ServerStorage.Leaf
local MAX_ITERATIONS = 5
local BASE_ANGLE = 45
local function generateTree(parentBranch: BasePart, iter: number)
local pivot = parentBranch:GetPivot()
local origin = CFrame.new(Vector3.xAxis * parentBranch.Size.X)
if iter > MAX_ITERATIONS then
local leaf = leafTemplate:Clone()
leaf:PivotTo(pivot * origin)
leaf.Size = leaf.Size * math.max(0.3, math.random() * 1.5)
leaf.Parent = parentBranch
return
end
local progress = iter / MAX_ITERATIONS
local baseAngle = math.lerp(0, BASE_ANGLE, progress)
local variation = 20 * (1 - progress * 0.5)
local droopAngle = baseAngle + math.random(-variation, variation)
local rotation = CFrame.Angles(
math.random() * 2 * math.pi,
math.rad(droopAngle),
0
)
local newBranch = parentBranch:Clone()
local newWidth = newBranch.Size.Y * 0.7
local newLength = newBranch.Size.X * 0.9
newBranch.Size = Vector3.new(newLength, newWidth, newWidth)
newBranch.PivotOffset = CFrame.new(Vector3.new(-newLength / 2, 0, 0))
newBranch:PivotTo(pivot * origin * rotation)
newBranch.Parent = tree
generateTree(newBranch, iter + 1)
local chance = math.max(0.1, 1.2 - progress * 0.8)
while math.random() < chance do
generateTree(newBranch, iter + 1)
chance *= 0.5
end
end
generateTree(root, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment