Example #1
0
    public void SetUpBody(GenerationSettings.PlanetSettings planetSettings, bool setPositions = true, CelestialBody newOrbitalParent = null)
    {
        // this is called when a celestial body is wanted to be set up as a planet

        GenericSetup(planetSettings);

        drawPath   = planetSettings.drawPath;
        pathLength = planetSettings.pathLength;

        if (setPositions)
        {
            // place the planet away from the star
            Vector3 direction = new Vector3(Mathf.Cos(planetSettings.offsetAngle * Mathf.Deg2Rad), 0, Mathf.Sin(planetSettings.offsetAngle * Mathf.Deg2Rad));
            transform.position = newOrbitalParent.transform.position + (direction * planetSettings.distance);
        }

        // set up the initial velocity
        // so that the planet will fall into a stable orbit around its parent
        // we do this even if we don't want to reset the position to calculate the effect
        // of any changes to the orbit eccentricity
        if (newOrbitalParent != null)
        {
            initialVelocity   = planetSettings.eccentricity * CalculateInitialVelocity(newOrbitalParent.transform);
            orbitalParent     = newOrbitalParent;
            orbitalParentMass = orbitalParent.GetComponent <CelestialBody>().mass;
        }
    }
Example #2
0
    void CreatePlanet(GenerationSettings.PlanetSettings planetSettings)
    {
        // create a new planet gameobject
        // make it a child of the solar system
        GameObject newPlanet = new GameObject
        {
            name = "Planet " + transform.childCount.ToString()
        };

        newPlanet.transform.parent = transform;

        // add components to the planet
        CelestialBody cbComponent = newPlanet.AddComponent <CelestialBody>();

        // assign the values to the planet from the settings
        cbComponent.SetUpBody(planetSettings, true, star);

        // then register it as a celestial body
        celestialBodies.Add(cbComponent);
    }