Been fighting with this for days. I have various GameObjects scattered throughout a spherical area. Center of the area is 0,0,0. (Think “solar system”.) All objects are instantiated as children of the center (“sun”) and have 0,0,0 rotation. Necessary to add LineRenderers between them (think “waypoints”) that stay linked if the whole system is rotated with the mouse.

The various GameObjects contain child structures (“planets”). What I want is to rotate the child structure so that its top is facing the “sun” at the center, and its forward is “toward” the next object. (Spun as close as it can get.)

I can get the top pointing at the center by using LookAt then rotating 90 degrees:

ThisChild.transform.LookAt(transform.parent.position, transform.up);
ThisChild.transform.Rotate(Vector3.right, 90f);

However, I can’t seem to figure out how to then rotate the Child’s local Y so that its forward is toward the next object. I can’t just use LookAt again, because I need the top fixed toward the center.

I’ve tried various techniques of getting vectors and dropping x and Z, for example. Nothing seems to work as the vectors are all in world space instead of relative to the child object.

Try this:

ThisChild.transform.LooAt(sun.position, transform.parent.position - transform.position);

The intent was that if you were standing on top of the “planet” using its transform, the “sun” would be high in the sky and the next “planet” would be somewhere in front of you. As that proved to be overly complicated to accomplish, I used robertbu’s suggestion:

ThisChild.transform.LookAt(NearestObject.transform.position, Sun.transform.position - ThisChild.transform.position);

That means you’d always be facing directly at the next “planet”, and the “sun” would be somewhere in the sky. Admittedly more organic and likely more useful than what I was trying to do.