- Home /
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!
Answer by CoughE · Jul 31, 2020 at 08:18 PM
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!
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Rotating a child and a parent, simultaneously 1 Answer
How to Prevent Child Deformation on Rotate? 1 Answer
Rotating around a parent 1 Answer