# Rotate multiple objects around a object, maintaining their own trajectory(not rotating their local forward vector)

I got a problem with rotations, the thing i am going for is basically something that looks like a atom.
You know, one of these things:

I need units to spin around a center object, and i need to be able to shoot as many units as i want to that center object, and those units than need to spin around it, based on the trajectory they had when the came into the gravitational pull of that center object basically.

I already have something working that does just about that, using something as :

``````var lookDirection : Vector3 = target.position - transform.position;
var rotation : Quaternion = Quaternion.LookRotation(lookDirection);
transform.rotation = Quaternion.Lerp(transform.rotation,rotation,randomLookspeed;
transform.Translate(Vector3.forward * randomSpeed);
``````

The problem with that, is that after a while all the units will be circling around that transform at the same height because each unit is lerped towards that. It will than look like a giant disc made up of units, or a galaxy like structure (cool, but not what i want), i want that atom effect.

Because the unit is always moving forward, rotating the local x axis should be enough to make it rotate around the center object while it is maintaining its own trajectory, but for some reason i can not get it done properly.

How can i set the Quaternion rotation so that visually it looks like the unit only rotates around the center object on its X axis?

your best bet is to use constraints. for each electron create an empty gameobject (parented to nucleus) where it should be located, then constrain the electron to the empty gameobject.

this should keep the electronâ€™s forward vector the same as the nucleus rotates. if after that you want to spin the electron you may want to write a script that updates its rotation as the nucleus spins. you could even use a lookat script, although to lock off one axis you may need to alter it slightly, so that it (for example) looks at the nucleus position in X and Z but its own y position.

hope this helps.