- Home /
 
Position gameObjects based on children
I have multiple GameObjects that can be connected. (Positioned right next to each other with an aligned rotation).

When two of the green balls collide, the white box should snap to the red box.
I have this method:
 void Snap(Connector ownConnector, Connector otherConnector)
 {
     GameObject whiteBox = ownConnector.parent;
     GameObject redBox = otherConnector.parent;
     // TODO
 }
 
               At the moment my code looks like this:
 Vector3 ownConnectorPosition = ownConnector.transform.localPosition;
 ownConnectorPosition = whiteBox.transform.rotation * ownConnectorPosition;
 whiteBox.transform.position = otherConnector.transform.position - ownConnectorPosition;
 
               This works great as long as the boxes are not rotated.
How can i rotate the whitebox so that it aligns with the red box? All the green connectors pointing away from their box with ther Z axis.
 
                 
                connectors.png 
                (96.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer