Moving the box according to camera's angle

I have two boxes, that first one is in the center of the scene, and the other one is near to the first box.
the camera is moving around the first box.

i want the second box to be always on the opposite side of camera’s angle.

for the second box circulation i’m using Quaternion, how ever i can not find the camera’s angle to adjust the second box angle


I didn’t really get what you are after, but have you tried adding the 2nd box as a child to the camera? And move it to the opposite side, it will always stay there wherever the camera moves.

1 Like

Ok, let me explain in other way

Suppose we want to make a solar system that contains the sun, the earth and the moon

I have 3 sphere
number 1 : it’s on center of scene and the camera rotate around it (sun)
number 2 : it’s on corner of scene (earth)
number 3 : it’s rotate around earth ( moon )

i can rotate camera around the sun with mouse movement

and i want to change moon’s position related to earth and camera !
the moon rotate around the earth ( with Quaternion ) but it’s angle depend on camera, it’s mean the moon always be direct to camera

my question is how can i find the camera’s angle related to the earth and then set it to moon ?

1 Like

If you don’t mind, I’ll call them Sun and Planet.

The easiest way I can think of is just position everything as you want, parent the moon to the Earth and the Earth to the Sun, and make the Sun to lookAt the camera always. Keep in mind that with this setup you’ll not be able to easily transform each element independently, but you may not require this.

Another option to get the Planet to be opposite to your camera, I would take the location of the camera, the location of the Sun, substract and see where the Planet should be located in reference to the Sun. Here I’m not using any rotation, so no Quaternions needed. With that, the Planet will always be hidden behind the Sun, but then you can rotate it with pivot in the center of the Sun or some similar adjustment.

I can think of more solutions, like using a sphere for the orbit and raycast, but the above should be enough.

1 Like

Thank you for reply
why does Sun lookAt the camera ?!

the point is, the moon must be direct to camera. when the camera rotate, the moon rotate around eath too but the angle of camera and moon must be same related to earth

If you parent the moon to the planet, and the planet to the earth, set up the camera and the planet as you want, by using lookAt I expect the sun to rotate automatically as the camera moves, and the planet will move acordingly. You should also be able to rotate the planet so the moon, which is parented, orbits it.

Check this out:

(I’ll delete this project this week as I don’t want it floating around in my menu, please take what you want as soon as possible).

Thank you
but it’s not what exactly i need
please make sun and eath to be static
and the moon must be change when camera moves

my problem is with moon, i want moon be direct to camera
no need to moon rotate automaticaly ! moon rotate when camera rotate around the sun

I removed the rotation script attached to the planet and replaced it with the lookAt script.