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 Radius = 0f;
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);
vec.z = Mathf.Cos(this.Theta) * this.Radius;
return vec;
}
public SphereCoordinate(Vector3 xyz)
{
this.Radius = Mathf.Sqrt(
Mathf.Pow(xyz.x, 2f) +
Mathf.Pow(xyz.y, 2f) +
Mathf.Pow(xyz.z, 2f)
);
this.Theta = Mathf.Pow(Mathf.Cos(xyz.z / this.Radius),-1);
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?