like the title says, im trying to create procedurally generated plants , similar to grow a garden. Right now, im trying to generate trees, and I am currently experiementing with L-systems. Im able to get the seed to generate for the l system, but im having some struggles with turning the actual seed into a plant.
currently, this is what i have (it doesnt work)
local generationRules = {
X = "F+[[X]-X]-F[-FX]+X",
F = "FF"
}
local originalWord = "-X"
local testPlant = game.ReplicatedStorage:WaitForChild("TestPlant")
local start = game.Workspace:WaitForChild("TestPlant")
local function readPlantSeed(word:string, start:Part, rotateAngle:number)
local stack = {} --reading branches
local currentExtrudeNode = start.ExtrudeNode
for i = 1, #word do
local char = word:sub(i, i)
if char == "F" then
local segment = testPlant:Clone()
local offset = segment.CFrame:ToObjectSpace(segment.ConnectorNode.CFrame)
segment.Parent = start
segment.CFrame = currentExtrudeNode.CFrame * offset:Inverse()
start = segment
currentExtrudeNode = segment.ExtrudeNode
elseif char == "+" then
--currentCFrame = currentCFrame * CFrame.Angles(0,0, math.rad(rotateAngle))
end
end
end
local function generatePlant(startObj, nodeCount, rotateAngle)
local nextChar = ""
local updatedWord = originalWord
for i = 1, nodeCount do
for i, v in ipairs(updatedWord:split("")) do
if generationRules[v] then
nextChar = nextChar..generationRules[v]
else
nextChar = nextChar..v
end
end
updatedWord = nextChar
nextChar = ""
print(updatedWord)
readPlantSeed(updatedWord, startObj, rotateAngle)
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input: InputObject, gpe: boolean)
if gpe then return end
if input.KeyCode == Enum.KeyCode.E then
generatePlant(start,2, 15)
end
end)
the segment