Skip to content

About

This Solar System Simulator simulates real-world gravitational physics using Unity's physics. Demonstrating Newton and Kepler’s laws in a 3D simulation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Solar System 3D Simulator Documentation

Unity Engine Simulation Project

Orbit Velocity Mass Fixed Mars and Jupiter Added

Overview

Genre: Simulation

Introduction

This Solar System Simulator project simulates real-world gravitational physics using Unity's physics. It demonstrates Newton and Kepler’s laws in a 3D simulation. The project was developed in Unity and uses NASA's APOD API (Astronomy Picture of the Day) to display photos taken in real-time each day.


Design

The project design is a replica of our solar system with all planets in orbit order. I also designed custom shaders and gathered textures from solarsystemscope.com to make the planets look somewhat similar to their real counterparts. I also used an outside space skybox to help create a more space aesthetic for the scene of the project. Splines were placed around the project to help assist viewers in getting a better look at each individual planet and our sun, so it would be easier to view and read any topics and information on the planets.

Solar System Model

Development

The solar system is designed to calculate all the GameObjects in the scene that derive from the CelestialBody.cs class into an array list. This was necessary for the calculations because the script runs the array list within a nested foreach loop and determines whichever gameObjects has the higher mass (M1) between two bodies; based on that, the body with the lower mass (M2) will move towards the body with the higher mass (M1).


    private void Gravity()
    {
        foreach (CelestialBody body1 in bodies)
        {
            foreach (CelestialBody body2 in bodies)
            {
                if (!body1.Equals(body2))
                {
                    float m1 = body1.mass;
                    float m2 = body2.mass;
                float r = Vector3.Distance(body1.transform.position, body2.transform.position);


                float UniversalGravitation = (G * (m1 * m2) / (r * r));

                body1.GetComponent<Rigidbody>().AddForce((body2.transform.position - body1.transform.position).normalized * UniversalGravitation);

            }

        }
    }
}

Kepler’s orbital velocity formula is implemented using nested foreach loops that compare each celestial body against every other body. The function ensures body1 (M1) and body2 (M2) are not the same object before calculating orbital velocity. The more massive body uses M2 as the reference point, continuously facing it while applying the calculated orbital velocity along its transform.right direction. This tangential force causes the object to move in an arc or circular orbit around the other body, with M2’s mass contributing to the orbital velocity calculation.



    private void OrbitalVelocity()
    {
        foreach (CelestialBody body1 in bodies)
        {
            foreach (CelestialBody body2 in bodies)
            {
                if (!body1.Equals(body2))
                {
                    float m2 = body2.mass;

                    //Distance
                    float r = Vector3.Distance(body1.transform.position, body2.transform.position);

                    body1.transform.LookAt(body2.transform);

                    //Orbital Velocity Formula
                    float orbitalVelocity = Mathf.Sqrt((G * m2) / r);

                    body1.GetComponent().linearVelocity += body1.transform.right * orbitalVelocity;
                }

            }
        }
    }
    
  

Technical Art

I designed a planetary shader that displays the planet's base image and height map to give the sphere body depth. I also create an atmosphere shader using the fresnel node to help assist in creating the effect of an atmosphere. This was helpful in displaying a close to similar replica of the planet models.

Shader Material Time-lapse: https://youtu.be/Q6FuDVtrD1M Earth_and_Sun_Motion

About

This Solar System Simulator simulates real-world gravitational physics using Unity's physics. Demonstrating Newton and Kepler’s laws in a 3D simulation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages