You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to connect pieces with connection points, and the connection type must be same to connect one. with no intersections. -
What is the issue? Include screenshots / videos if possible!
my recursive generation does not check intersections, it makes a garbled mess and impossible to pass the people through.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
nothing I dealt with that intersecting thing, and I didn’t search that
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
pieces = script.JigsawPieces:GetChildren()
RecursiveConnectPieces = function(connector,jigsawpieces)
local compatiblepieces = {}
local randomize = 0
for _,i in pairs(jigsawpieces) do
for _,j in pairs(i:GetChildren()) do
if j.Name == "Connector" then
if connector:GetAttribute("ConnectionType") == j:GetAttribute("ConnectionType") then
compatiblepieces[#compatiblepieces+1]={i,i:GetAttribute("Probability")}
randomize = randomize + i:GetAttribute("Probability")
break
end
end
end
end
--print(#compatiblepieces)
--print(compatiblepieces)
local resu = 1
while true do
if compatiblepieces[resu][2] > math.random(0,randomize) then break end
randomize = randomize - compatiblepieces[resu][2]
resu = resu + 1
if resu == #compatiblepieces then break end
end
--print(compatiblepieces[resu][1])
resu = compatiblepieces[resu][1]:Clone()
local compatibleconnectors = {}
for _,i in pairs(resu:GetChildren()) do
if i.Name == "Connector" then
if connector:GetAttribute("ConnectionType") == i:GetAttribute("ConnectionType") then
compatibleconnectors[#compatibleconnectors+1]=i
end
end
end
--print(#compatibleconnectors)
local connected = compatibleconnectors[math.random(1,#compatibleconnectors)]
resu.PrimaryPart = connected
resu:SetPrimaryPartCFrame(connector.CFrame:ToWorldSpace(CFrame.new(0, 0, -1)*CFrame.Angles(0,math.rad(180),0)))
resu.Parent = script
connected:Destroy()
local compatibleconnectors = {}
for _,i in pairs(resu:GetChildren()) do
if i.Name == "Connector" then
wait()
RecursiveConnectPieces(i,jigsawpieces)
end
end
connector:Destroy()
end
RecursiveConnectPieces(script.Seed.Connector,pieces)
print("generation finished")
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category