Need help with my custom dungeon generator!

Godot Version

4.2.1

Question

I want to make a unique dungeon generator, where instead of tile maps, I would use premade rooms with connectors placed at the entrances and exitways of rooms, to indicate where to put another random room. So far I can place rooms where connectors are, but I am having issues with rotating rooms, in order to have pathways.

Here’s the folder on GitHub with dungeon generation test. There is a main scene dungeon_generator.tscn and 2 room test scenes.

The code is boiling down to finding 2 random connectors in the scene and in room list and connecting them by positioning connectors into each other and then rotating them accordingly.
I am a bit lost at this point with how rotate a room, so it wouldn’t go into itself, and would support pathways, that are diagonal (i.e. not in 90 degree increments), so any help would be appreciated!

Code for Dungeon Generator root scene

extends Node3D

@export var roomList = []
@onready var roomContainer = get_node("roomsContainer")

func add_room():
	randomize()
	if roomContainer.get_child_count() == 0:
		var room : Room3D = roomList.pick_random().instantiate()
		room._fill_con_list()
		roomContainer.add_child(room)
	else:
		var existingRoom = roomContainer.get_children().pick_random()  # before instantiating
		var openConnector : Connector3D
		
		while openConnector == null:
			openConnector = check_connectors(existingRoom)
			if openConnector == null:
				existingRoom = roomContainer.get_children().pick_random()
		# maybe when no connections left do something
		
		var room : Room3D = roomList.pick_random().instantiate()
		room._fill_con_list()
		var roomConnector : Connector3D = room.connectorList.pick_random()
		roomContainer.add_child(room)
		
		roomConnector.isOccupied = true
		openConnector.isOccupied = true
		
		#position room
		room.position = openConnector.global_position
		room.translate(roomConnector.position * -1)
		
		#rotate room : NOTE it's a placeholder code, not really functional
		room._change_rotating_root(roomConnector)

		if openConnector.rotation[1] == 0:
			roomConnector.rotation_degrees[1] = 180
		elif openConnector.rotation_degrees[1] > 0:
			roomConnector.rotation_degrees[1] = 180 + openConnector.rotation_degrees[1]
		else:
			roomConnector.rotation_degrees[1] = - 180 + openConnector.rotation_degrees[1]


func check_connectors(room : Room3D):
	for connector : Connector3D in room.connectorList:
			if !connector.isOccupied:
				return connector

func _on_button_pressed():
	add_room()

Code for a Room3D class:

class_name Room3D extends Node3D

var connectorList : Array

func _fill_con_list() -> void:
	if len(connectorList) == 0:
		connectorList = get_node("Targets").get_children()
	else:
		connectorList.clear()
		for node in get_node("Targets").get_children()[0].get_children():
			if node.is_class("Marker3D"):
				connectorList.append(node)

func _change_rotating_root(connector : Connector3D) -> void:
	if connector in connectorList:
		var model = get_node("Model")
		model.reparent(connector)
		for leftConnector : Connector3D in get_node("Targets").get_children():
			if !leftConnector.isOccupied:
				leftConnector.reparent(connector)
		_fill_con_list()
	else:
		printerr("No connector in the list!")

Code for Connector3D, markers where pathways are placed^

class_name Connector3D extends Marker3D

var isOccupied : bool = false

func _process(delta):
	if isOccupied:
		get_child(0).visible = true