Game object 1 with child transform (empty gameobject as a child)
Game object 2 with child transform (empty gameobject as a child)
Goal:
Align game object 2’s position and rotation with the game object 1 transform. Game object 2 needs to be aligned via its child transform (empty game object with only a transform). Also want to end up with the same hierarchy as we started with as the final result.
Current Approach - hoping for more optimized solution or easier to read / shorter:
make child of game object 2 the
‘parent’ of game object 2 (it keeps
its relative position this way)
move the now ‘parent’ to game object
2 to the destination game object 1
transform (via transform.position
and rotation - easy enough)
make the game object 2 the ‘parent’ of its original child object transform
Obviously changing the parent / child several times gets old to type (i can make it a function yes) but it still seems slow / not required. Also consider that both game object 1 and 2 are child objects to yet another object in the scene (for both organization and movement). I tried Transform.Translate as it seemed to be the correct thing, but it didn’t provide the correct results when testing, I could have just had something misplaced.
I can provide REAL code if required, this is a c# project but I can totally understand javascript, post whatever you feel is appropriate - THANKS!
Edit Image Attached
Note that if half the rod is missing (as shown in the image) the overlap is visible in the objects i’m using, thus why i mention the visual issue (besides potential collider, center of mass and other physics issues)
This thread helped me solve a problem that was plaguing me for ages - namely lining up coordinate systems of two different 3d tracking systems - thanks a lot! I used EthanF4D’s method ultimately - see my reply to this question: Align HTC Vive Coordinate with OptiTrack System in Unity - Unity Answers