# Planet moves

Hey guys,

ich want to create solar systems with moving planets.
My program generates some planets randomly.
Now i want to move them in a random direction.

I tried to move them on the sphere coordinate of the solar system.
But it dosn’t work.

Here is my code:

``````public class SphereCoordinate
{
public float Theta = 0f;
public float Phi = 0f;

public Vector3 ToXYZ()
{
Vector3 vec = new Vector3(0, 0, 0);

vec.x = Mathf.Sin(this.Theta) * this.Radius * Mathf.Cos(this.Phi);
vec.y = Mathf.Sin(this.Theta) * this.Radius * Mathf.Sin(this.Phi);

return vec;
}

public SphereCoordinate(Vector3 xyz)
{
Mathf.Pow(xyz.x, 2f) +
Mathf.Pow(xyz.y, 2f) +
Mathf.Pow(xyz.z, 2f)
);

this.Phi = Mathf.Pow(Mathf.Sin(xyz.y / (Mathf.Sin(this.Theta) * this.Radius)), -1);
}
}
``````

Edit:
this function will be called from every planet.

``````public class SolarSystemMove : MonoBehaviour {

public Transform SolarSystemCenter;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void LateUpdate ()
{
if (SolarSystemCenter)
{
Vector3 kugko = transform.position - SolarSystemCenter.transform.position;
SphereCoordinate kk = new SphereCoordinate(kugko);
float ntheta = kk.Theta += 1f;

print(ntheta);
if (ntheta > 360)
{
ntheta = 360 - ntheta;
}
kk.Theta = ntheta;
transform.position = kk.ToXYZ() + SolarSystemCenter.transform.position;
}
}
}
``````

Can anyone help me?

Why not use some of the builtin functions for that, like Transform.RotateAround? Saves a lot of time to not reinvent the wheel for this.

thx
i didn’t know there are a function like this.