This mostly is a scripting problem, but still requires some building. I’m making a procedurally generated game (kind of like a dungeon game) and my problem is that rooms are spawning inside of eachother. The way my engine works is there is one base room with several doors that lead to new rooms each time with more doors and so on. Each room has a hitbox to tell if it intercepting another room. But when it spawns inside itself, it thinks that is not inside of a room. Here is my code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local floor = ReplicatedStorage.Floor
local start = workspace.Start
function Create(model)
local doors = model.Doors:GetChildren()
for i=1, #doors do
local floorNum = math.random(1,#ReplicatedStorage.Floor:GetChildren())
local newFloor = ReplicatedStorage.Floor:GetChildren()[floorNum]:Clone()
newFloor.Parent = workspace.New
local newDoors = newFloor.Doors:GetChildren()
local randomNum = math.random(1,#newDoors)
newFloor.PrimaryPart = newDoors[randomNum]
newFloor:SetPrimaryPartCFrame(doors[i].CFrame)
if #newFloor.hitbox:GetTouchingParts() > 0 then
newFloor:SetPrimaryPartCFrame(newDoors[randomNum].CFrame * CFrame.Angles(0,math.rad(180),0))
end
if #newFloor.hitbox:GetTouchingParts() > 0 then
newFloor:Destroy()
else
newDoors[randomNum]:Destroy()
newFloor.hitbox.CanCollide = false
end
doors[i]:Destroy()
end
model.Parent = workspace.Old
end
Create(start)
for i = 1,10 do
local children = workspace.New:GetChildren()
for _, child in ipairs(children) do
Create(child)
end
end
Some video because I am a confusing writer. btw the purple things are the hitboxes. if they are a deeper shade, that means they have piled up. also, im not a very advanced scripter, so my code might be not very optimized.
thanks