I have been working on a dungeon generation system, and most of the time some of the rooms miss-place.
Here are some of the images that show problems:
The first one shows the rooms leaving an empty corner.
The second one shows a room miss-placed.
This is the generation script inside of (ServerScriptService):
local PathFindService = game:GetService("PathfindingService")
local Generated = Instance.new("Folder", workspace)
Generated.Name = "Generated"
local Rooms = game.ReplicatedStorage.Rooms:GetChildren()
for I, V in pairs(workspace.Grid:GetChildren()) do
if V:IsA("Model") then
-- None
else
V.Transparency = 1
end
end
for I, V in pairs(Rooms) do
V.PrimaryPart = V.Floor
end
local Rotations = {0, 90, 180, 270} -- Rotations for the rooms
local function Generate()
Generated:ClearAllChildren()
for I, V in pairs(workspace:FindFirstChild("Grid"):GetChildren()) do
if V:IsA("Model") then
-- None
else
local ChosenRoom = Rooms[math.random(1, #Rooms)]:Clone()
ChosenRoom:SetPrimaryPartCFrame(V.CFrame * CFrame.Angles(0, math.rad(Rotations[math.random(1, #Rotations)]), 0))
ChosenRoom.Parent = Generated
end
end
end
wait(3)
local Path
repeat wait()
Generate()
Path = PathFindService:CreatePath()
Path:ComputeAsync(workspace.Grid.Start.Floor.Position, workspace.Grid.End.Floor.Position)
until Path.Status == Enum.PathStatus.Success
Here are some images of the properties I’m using right now:
The first one is the floor. This is where the rooms will spawn.
The second one is the wall. The Y is the height of the walls.
If anyone knows how to help, let me know!