Align two parents based on child position and rotation

Hi all,

I have two rooms (the parents), each with a connection point (the children). I am trying to align the parents such that the two connections points connect. Here is an example of what i’m trying to do.

So lets say P1 is the gray room on the left with the green connector, and P2 is the room on the right with the red connector.

Using This link, I am able to position them somewhat correctly, but they don’t rotate correctly. It also doesnt take into account the rotation of the individual connectors. As I tried to demonstrate in the picture, the connectors point outwards, and the red one should basically match the green connectors rotation but inversed 180 degrees.

Does anyone have an idea on how I should go about this? Quaternion math is definitely a subject I need to brush up on. Thanks for your time!

So I stopped trying to make it complicated and instead used my good ol’ brain to do some work! Instead of dealing with super messy quarternions, I just used the .forward of each connector!

Here’s what I came up with.

     //Rotate to be the room connector but facing the opposite direction
        Quaternion rot = Quaternion.FromToRotation(newRoomConnectedPt.forward, -roomConnection.forward);
        newRoomT.rotation = rot * newRoomT.rotation;
        //Set room to be positioned at the connector, and then apply an offset so instead of using the rooms position, youre using the connectors positions
        newRoomT.position = roomConnection.position - (newRoomConnectedPt.position-newRoomT.position);

Hope this helps anyone looking!