Example #1
0
    public void SetUpBody(GenerationSettings.StarSettings starSettings, bool setPositions = true)
    {
        // this is called when a celestial body is wanting to be set up to be a star

        // add a rigidbody to the body
        if (rb is null)
        {
            rb = gameObject.AddComponent <Rigidbody>();
        }

        // set the type of body
        bodyType = starSettings.bodyType;

        // set up the visual sphere here
        visualSphere = new GameObject(gameObject.name + " visuals");
        visualSphere.transform.parent = transform;

        //CelestialBodyMesh meshConstructor = visualSphere.AddComponent<CelestialBodyMesh>();
        //meshConstructor.Generate(starSettings.structureSettings, starSettings.colorSettings);

        // set the properties of the body from the settings
        surfaceGravity = starSettings.surfaceGravity;
        radius         = starSettings.radius;
        mass           = radius * radius * surfaceGravity / Universe.gravitationalConstant;
        axisTilt       = starSettings.axisTilt;
        axialSpinSpeed = starSettings.axialSpin;

        Quaternion upRot = Quaternion.AngleAxis(axisTilt, Vector3.forward);

        localUpAxis = upRot * Vector3.up;

        StarMesh sm = visualSphere.AddComponent <StarMesh>();

        sm.Setup(starSettings.temperature);

        // set up the transform
        transform.localScale = Vector3.one;
        visualSphere.transform.localScale    = Vector3.one * radius * 2;
        visualSphere.transform.localRotation = upRot;

        // setup the rigidbody
        rb.mass = mass;

        // each object is given a unique id that is generated through its settings
        ID = starSettings.id;

        if (setPositions)
        {
            // set up the initial velocity
            // for a star in a single star system, we dont need initial velocity
            // as the star is not moving initially relative to all other objects
            // in the system
            initialVelocity = Vector3.zero;
            rb.position     = Vector3.zero;
        }
    }
Example #2
0
    void GenericSetup(GenerationSettings.CelestialBodySettings newSettings)
    {
        // add a rigidbody to the body
        if (rb is null)
        {
            rb = gameObject.AddComponent <Rigidbody>();
        }

        // set the type of body
        bodyType = newSettings.bodyType;

        // set up the visual sphere here
        visualSphere = new GameObject(gameObject.name + " visuals");
        visualSphere.transform.parent = transform;

        CelestialBodyMesh meshConstructor = visualSphere.AddComponent <CelestialBodyMesh>();

        meshConstructor.Generate(newSettings.structureSettings, newSettings.colorSettings);

        // set the properties of the body from the settings
        surfaceGravity = newSettings.surfaceGravity;
        radius         = newSettings.radius;
        mass           = radius * radius * surfaceGravity / Universe.gravitationalConstant;
        axisTilt       = newSettings.axisTilt;
        axialSpinSpeed = newSettings.axialSpin;

        Quaternion upRot = Quaternion.AngleAxis(axisTilt, Vector3.forward);

        localUpAxis = upRot * Vector3.up;

        // set up the transform
        transform.localScale = Vector3.one;
        visualSphere.transform.localScale    = Vector3.one * radius;
        visualSphere.transform.localRotation = upRot;

        // setup the rigidbody
        rb.mass = mass;

        // each object is given a unique id that is generated through its settings
        ID = newSettings.id;
    }