#Room generation issues

1 messages · Page 1 of 1 (latest)

digital knoll
#

Hey all, I have a script that pulls rooms from a folder in ReplicatedStorage and generates repeatedly whereever there is an exit in these rooms. I attempted to implement a check for if an exit is colliding with another room, and if it does, do not generate a room there.

However, this doesn't seem to be working and rooms can generate on top of eachother. Any ideas how to fix this? ❤️

#

forgot to put the full code snippet in text format. whoopsies

    local poolFolder = roomsFolder:WaitForChild(level.Name)
    local rands = poolFolder:WaitForChild("_random")
    
    local roomsGenerated = 0
    local finalRoom = nil
    
    local function generate(fromRoom)
        for i, v in ipairs(fromRoom:GetChildren()) do
            if v:IsA("BasePart") and v.Name == "_roomOut" then
                local partsInCheck = workspace:GetPartsInPart(v)
                
                if roomsGenerated < limit and #partsInCheck == 0 then
                    local newRoom = rands:GetChildren()[math.random(1, #rands:GetChildren())]:Clone()
                    newRoom.Parent = scene
                    
                    newRoom:SetPrimaryPartCFrame(v.CFrame)
                    roomsGenerated += 1
                    
                    finalRoom = newRoom
                    task.spawn(generate, newRoom)
                end
            end
        end
    end
    
    --// force start room
    local startRoom = poolFolder:WaitForChild("_START"):Clone()
    startRoom.Parent = scene
    startRoom:WaitForChild("_levelStart").Parent = level:WaitForChild("_core")
    roomsGenerated += 1
    
    generate(startRoom)
    
    while roomsGenerated < limit do
        task.wait()
    end
    
    --// put all the rooms in an array
    local exitRoom = poolFolder:WaitForChild("_FINISH"):Clone()
    exitRoom.Parent = scene
    
    exitRoom:SetPrimaryPartCFrame(finalRoom.PrimaryPart.CFrame)
    exitRoom:WaitForChild("_exitLocation").Parent = level:WaitForChild("_core")
    
    finalRoom:Destroy()
end```
acoustic bay
#

Make a part and see if it collides with anything that is a child of the folder

#

If it does not then you can spawn it

#

Else close the door

#

Theres also 2 other ways

#

Partsinsidebox()

#

Or sum like that

#

And raycast

digital knoll
#

i initially had partsinsidebox but that was pretty annoying to get my head around
raycasting might work tho

#

idk i just feel that this bit should've worked
i tried adding prints to check too, the room still generates when it flags an overlap which is strange

#

but ill try a raycasting method

acoustic bay
#

Keep in mind that raycasting is a line and not a hitbox

digital knoll
#

yep

obsidian cipherBOT
#

studio** You are now Level 9! **studio

digital knoll
#

might not be the most ideal then..

acoustic bay
#

You can always just spawn a part

#

Or just spawn the actual structure and see if that collides

#

Might be more laggy tho

#

And buggy

#

Bc if it collides with itself

digital knoll
#

yeah...

acoustic bay
#

But still

#

Try the part meathod

digital knoll
#

aight

#

that works???
i dont understand why checking with the room exit didn't lmao

#

i feel so stupid now lols

#

gonna run a few more tests to make sure it 1000% works

acoustic bay
#

Alr happy to help! 👍

#

The room exist might have collided with the floor or walls of its own room

digital knoll
#

okay i finally got it down, i had to make the checker part wider than the roomOuts, then i had to check if the part it was colliding with is not parented to the room it is branching from
very convoluted lol but it works now

#

thx so much for the help ❤️ ❤️ ❤️