How to place the new procedural generated room? (Position and Rotation)

Trying to make a procedural dungeon generation, but now, how do I make for the new rooms spawn right in front of the waypoint instead of inside of it?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AssetsFolder = ReplicatedStorage:WaitForChild("AssetsFolder")
local Rooms = AssetsFolder:GetChildren()

local StartPos = Vector3.new(0, 0, 0)
local MaxRooms = 100

print(Rooms)

local function Generate(StartPos, MaxRooms)

	local LastRoomGenerated

	--Spawn First Room
	local StarterRoom = AssetsFolder.StarterRoom:Clone() :: Model
	StarterRoom.Parent = workspace
	
	table.remove(Rooms, table.find(Rooms, StarterRoom))

	local AmountOfRoomsGenerated = 1
	LastRoomGenerated = StarterRoom

	--Generation	
	while AmountOfRoomsGenerated < MaxRooms do
		wait(0.125)
		for _, waypoint in LastRoomGenerated:GetChildren() do
			if waypoint.Name == "Waypoints" then
				
				local RandomRoom = Rooms[math.random(1, #Rooms)]:Clone() :: Model

				RandomRoom.Parent = workspace.Generation
				RandomRoom:PivotTo(waypoint.CFrame)
				
				AmountOfRoomsGenerated += 1
				LastRoomGenerated = RandomRoom
				
			end
		end
	end
	
	print("done")
end

Generate(StartPos, MaxRooms)

This will 100% help you with procedural generation logic:

2 Likes

I know the logic behind it. I just wanna know how I can space room between rooms. But I appreciate it anyways!

add start and and end attachments to all rooms and then just do the griffpatch maze logic to check for empty space then align the room using attachments (pivot room to the previous room after adding the attachment’s position and orientation to the rooms position and orientation)
@Yayn_y

But how do I do this in the script?

local position = previousRoom.CenterAtt.Position + previousRoom.EndAtt.Position - randomRoom.StartAtt.Position
local r = previousRoom.CenterAtt.Orientation + previousRoom.EndAtt.Orientation - randomRoom.StartAtt.Orientation

RandomRoom:PivotTo(CFrame.new(position) * CFrame.Angles(math.rad(r.X), math.rad(r.Y), math.rad(r.Z)))