VR Gravity Simulation

An in progress gravity simulation for use with google cardboard.

This is a work in progress of a VR gravity simulation.  I hope to eventually deploy this as a free application for use in visualizing planetary orbit.  It currently functions in a google cardboard headset and allows the user to spawn in planets at their discretion and clear the board by triggering the red object at the top.  I am in the process of adding the additional functionality of letting the user draw initial vectors for new planets in both a 2D and 3D environment, adjust the mass of the planet and creating a better user interface. I am also working on new art assets for the game as most objects are primitive shapes.

There is a great community for development in Unity and I have utilized many online resources to accomplish what I specifically want.  I will share the manager script (in C#) for the game that generates new planets based on user input.  The script is still in progress as I hope to better implement what I have and implement the previously stated functionality.
VR View
//A piece of the game manager script in charge of spawning in new planets
void Update ()
    {
        if (Input.GetButtonDown ("Fire1")) {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            Plane hPlane = new Plane (Vector3.up, Vector3.zero);
            float distance = 0; 
            if (hPlane.Raycast (ray, out distance)) {
                Vector3 location = ray.GetPoint (distance);
                            
                //provide initial vectors until user input functionality is added
                newPlanet = (GameObject)Instantiate (planet, Vector3.ClampMagnitude (location, spawnRadius), transform.rotation);
                if (location.x > 1) {
                    newPlanet.GetComponent<Rigidbody> ().AddForce (0, 0, 2000);
                } else if (location.x < 1) {
                    newPlanet.GetComponent<Rigidbody> ().AddForce (0, 0, -2000);
                } else {
                    newPlanet.GetComponent<Rigidbody> ().AddForce (0, 0, 1000);
                }

                //generate value to assign a material randomly
                int matGen = Random.Range (0, 4) + 1;
                switch (matGen) {
                case 1:
                    planet.GetComponent<Renderer> ().material = mat01;
                    break;
                case 2:
                    planet.GetComponent<Renderer> ().material = mat02;
                    break;
                case 3:
                    planet.GetComponent<Renderer> ().material = mat03;
                    break;
                case 4:
                    planet.GetComponent<Renderer> ().material = mat04;
                    break;
                }
            }
        }
    
    }
Back to Top