Hello all. I have having some trouble alinging two parent objects, according to their child objects.
In this picture, the blue squares are the parents, while the red dots are the children I am trying to align by. The yellow line is the rotation of the children.
Positioning them at the same world spot is easy,
parentPosition =otherParentsChildWorldPos- thisParentsChildsLocalPosition;
Now rotating them so that the rotation are the inverse of each other is proving to be more difficult.
I have tried ways such as
var desiredRot = otherChild.transform.eulerAngles - thisChild.transform.eulerAngles;
var offsetBetweenParentAndItsChild= thisChild.transform.localEulerAngles;
parent.transform.rotation = Quaternion.Euler(-otherChild.transform.eulerAngles + offsetBetweenParentAndItsChild);
But it provides wonky results when you rotate the parent from a rotation other than 0,0,0.
Any ideas?
A possible theory are somehow treating the child position as the origin on the parent (even when it’s not), and rotating from there?