Hello, I’m working on a chemistry game and I’m trying to make a procedurally generated skill tree so the players can easily look up what chemical to make next.
But as you can see, I don’t know how to limit the angles so they stop overlapping.
I would like the nodes to go around the main chemical in full 360 degrees (which they already do)
But I need a way to limit the angles of secondary nodes:
(do not steal my masterpiece artwork, I forgot to watermark it)
This is my code:
local function makeTree(ID: number, sT: GuiObject, prev: GuiObject?): ()
if not sT then return end
local Pages, PgAMT = getPages(ID)
local i = 0
local angle = 360 / (PgAMT[cPage] or 1)
for Item, Combinor in pairs(Pages[cPage] or {}) do
i += 1
local Line = Instance.new("Frame")
Line.Size = UDim2.new(0, L_SIZE, 0, 5)
Line.AnchorPoint = Vector2.new(.5, .5)
Line.Rotation = (i + (prev and 1 or 0)) * angle
Line.Position = sT.Position
Line.ZIndex = 0
Line.BackgroundColor3 = Color3.fromRGB(22, 28, 36)
local x, y =
L_SIZE * math.cos(math.rad(Line.Rotation)),
L_SIZE * math.sin(math.rad(Line.Rotation))
local sX, sY = sT.Size.X.Offset, sT.Size.Y.Offset
Line.Position += UDim2.new(0, x - x / 3, 0, y - y / 3)
Line.Parent = SkillTree
Kill[sT] = Kill[sT] or {Rely = Kill[prev]}
table.insert(Kill[sT], Line)
local sT2 = STemplate:Clone()
sT2.Icon.Image = SubstanceManager.IDs[Item].Main.Info.Icon.Texture
sT2.Position = sT.Position + UDim2.new(0, x, 0, y)
sT2.Name = Item
sT2.Parent = SkillTree
table.insert(Kill[sT], sT2)
makeTree(Item, sT2, sT)
end
end
The “get pages” function returns a table of every secondary node that has to be attached to the given node.
Then it creates a secondary node and a connecting line and rotates, offsets them.
The kill table is just a fancy way of cleaning the nodes.
Any help appreciated!