Hi, I'm generating dungeon rooms which connect at exits which are empties where doors would be, but I can't figure out the math to place them correctly. Here's the current functionality and a screenshot. This is for a game jam as well so it's slightly urgent.
foreach(DungeonRoomExit exit in exit_nodes)
{
if (!exit.occupied)
{
int rand = Mathf.FloorToInt(Random.Range(0, room_prefabs.Count));
DungeonNode new_room = Instantiate(room_prefabs[rand]);
int rand2 = Mathf.FloorToInt(Random.Range(0, new_room.exit_nodes.Length));
// find the new rotation of the new room
float new_rot = new_room.exit_nodes[rand2].transform.rotation.eulerAngles.y + new_room.exit_nodes[rand2].transform.rotation.eulerAngles.y;
new_room.transform.rotation = Quaternion.Euler(new Vector3(0, new_rot, 0));
new_room.transform.position = exit.transform.position - new_room.exit_nodes[rand2].transform.localPosition;
// draw connection
Debug.DrawLine(exit.transform.position, new_room.exit_nodes[rand2].transform.position, Color.red, 60f);
new_room.exit_nodes[rand2].occupied = true;
exit.occupied = true;
return;
}
}