I’m trying to make a map generator that works as follows:
Select random door on plot1, select random door on plot 2, connect two doors, if bounds of plot2 contain other plot bounds, try a different combo of doors. It just repeats this until it works.
but for some odd reason, its planting itself in places where it clearly has parts called “Bound” within itself.
has anyone else tried something like this? Even if not, some advice on random map generation (with man-made areas to connect with one-another) would be really helpful.
edit: my code, forgot to put it here :\
local Process = {
GenTable = {
-- % of total (25 + 25 = 50 which is same as 40 + 40 = 80)
25; -- Room
25; -- Connector
5; -- Arena
1; -- Monument
}
}
function Process:Acquire(name)
local storage = game.ReplicatedStorage.LVLS_STOR.LVLS
local level = storage:WaitForChild(name)
if level then
return level
end
end
function Process:ConnectWays(a,b)
local room = a.Parent
room.PrimaryPart = a
room:SetPrimaryPartCFrame(b.CFrame * CFrame.fromEulerAnglesXYZ(0,math.pi,0))
end
function Process:GetRoom(g)
local chil = g:GetChildren()
return chil[math.random(1,#chil)]
end
function Process:GetPath(r,t)
local list = {}
for _, i in pairs(r:GetChildren()) do
if i.Name == t then
table.insert(list,i)
end
end
return list[math.random(1,#list)]
end
function Process:Generate(name)
local level = game.ReplicatedStorage.LVLS_STOR.TEMP.MapName --Process:Acquire(name)
if level then
local lastroom
lastroom = Process:GetRoom(level.Connector):Clone()
lastroom.Parent = workspace
for i = 1,100 do
local worked = false
local room
room = Process:GetRoom(level.Connector):Clone()
room.Parent = workspace
local list = {}
for _, i in pairs(lastroom:GetChildren()) do
if i.Name == "Doorway" then
table.insert(list,i)
end
end
for try = 1,#list do
if (not worked) then
local randomnumber = math.random(1,#list)
local tryroom = list[randomnumber]
local list2 = {}
for _, i in pairs(room:GetChildren()) do
if i.Name == "Doorway" then
table.insert(list2,i)
end
end
for n = 1,#list2 do
if (not worked) and #list2 > 0 then
local randomnumber2 = math.random(1,#list2)
local tryroom2 = list2[randomnumber2]
Process:ConnectWays(tryroom2,tryroom)
local check = false
for _, b in pairs(room:GetChildren()) do
if b.Name == "Bound" then
local op = OverlapParams.new()
op.FilterType = Enum.RaycastFilterType.Blacklist
op.FilterDescendantsInstances = {room}
local partsinbound = workspace:GetPartBoundsInBox(b.CFrame,b.Size,op)
local inbound = false
for _, inpart in pairs(partsinbound) do
if inpart.Name == "Bound" then
inbound = true
end
end
if not inbound then
for _, e in pairs(room:GetChildren()) do
e.BrickColor = BrickColor.Random()
end
lastroom = room
tryroom2:Destroy()
tryroom:Destroy()
worked = true
else
table.remove(list2,randomnumber2)
end
end
end
end
end
table.remove(list,randomnumber)
end
end
if not worked then
room:Destroy()
end
end
else
warn("NO LEVEL")
end
end
return Process