IEnumerator Generate()
        {
            while (true)
            {
                GameObject     comet = Instantiate <GameObject>(model);
                CelestialOrbit orbit = comet.GetComponent <CelestialOrbit>();
                if (orbit == null)
                {
                    orbit = comet.AddComponent <CelestialOrbit>();
                }

                comet.transform.parent     = transform;
                comet.transform.localScale = Vector3.one * Random.Range(sizeRange.x, sizeRange.y);

                orbit.eccentricity = Random.Range(eccentricityRange.x, eccentricityRange.y);
                orbit.periapsis    = Random.Range(semiMajorAxisRange.x, semiMajorAxisRange.y);
                orbit.period       = Random.Range(periodRange.x, periodRange.y);

                orbit.limits      = new Vector2(-360, 360);
                orbit.meanAnomaly = -360f;

                orbit.longitude   = Random.Range(-180, 180);
                orbit.inclination = Random.Range(-180, 180);
                orbit.argument    = Random.Range(-180, 180);

                orbit.ResetSimulation();

                comet.SetActive(true);

                DestroyOnDisable destroy = comet.AddComponent <DestroyOnDisable>();
                orbit.OnOrbitEnd.AddListener(destroy.OnDisable);

                yield return(new WaitForSeconds(rate));
            }
        }
        GameObject GenerateBody(GameObject parent, string name, Color color, Vector2 eccentricityRange, Vector2 distanceRange, Vector2 sizeRange)
        {
            GameObject orbitObj = new GameObject(name);

            orbitObj.transform.parent        = parent.transform;
            orbitObj.transform.localPosition = Vector3.zero;

            //add an orbit component, and fill it out
            CelestialOrbit orbit = orbitObj.AddComponent <CelestialOrbit>();

            orbit.periapsis    = Random.Range(distanceRange.x, distanceRange.y);
            orbit.eccentricity = Random.Range(eccentricityRange.x, eccentricityRange.y);
            orbit.inclination  = Random.Range(inclinationRange.x, inclinationRange.y);
            orbit.longitude    = Random.Range(longitudeRange.x, longitudeRange.y);
            orbit.argument     = Random.Range(argumentRange.x, argumentRange.y);
            orbit.meanAnomaly  = Random.Range(-180f, 180f);
            orbit.ComputeStaticProperties();             //need to do this so that semi major axis is available
            orbit.period = 2 * Math.PI * Math.Sqrt(orbit.semiMajorAxis * orbit.semiMajorAxis * orbit.semiMajorAxis / gravitationParameter);

            //create the model for the body
            GameObject planetObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            planetObj.GetComponent <Renderer>().material.color = color;
            planetObj.transform.parent        = orbitObj.transform;
            planetObj.transform.localScale    = Random.Range(sizeRange.x, sizeRange.y) * Vector3.one;
            planetObj.transform.localPosition = Vector3.zero;

            return(orbitObj);
        }
Ejemplo n.º 3
0
        void Awake()
        {
            orbit = GetComponent <CelestialOrbit>();

            semiMajorAxisOriginal = orbit.periapsis;
            argumentOriginal      = orbit.argument;
            periodOriginal        = orbit.period;
        }
Ejemplo n.º 4
0
        void Awake()
        {
            line = GetComponent <LineRenderer>();

            if (orbit == null)
            {
                orbit = GetComponent <CelestialOrbit>();
            }
        }