Planet Gravity Sandbox

December 11, 2023
Tools: Unity

Introduction

This project was my final for Game Physics in my 3rd year at Champlain College. The goal of this project was to be able to spawn and edit planets that would orbit around the sun in the middle of the screen. This project includes editing planets in real time, pausing the simulation, planet collisions, and gravity.

GitHub

Theory

The system follows the formula for orbital speed, so implementing this into the project was the first step. Using Unity’s systems such as vectors and rigid bodies, the implementation of the physics came down to this function.

a

Although the sun in the center has the most amount of gravitational pull, the other planets can also pull each other if they have enough mass. Using the formula for orbital velocity and translating it to code we are able to allow objects in the scene to affect each other.

a

Sandbox

The main mechanics of a sandbox simulation is being able to place, delete, and edit objects while the simulation is running. Adding the CelestialBody component, the script that allows an object to be affected by the simulation’s physics, onto a prefab and spawning it in on mouse click will allow us to spawn in planets into the simulation wherever we want.

a

Next we need to be able to edit an object. By storing the object’s data in each object and getting that component when we click on it we can show a UI menu with the current attributes of a planet. In this project I implemented features to change the mass/size of the planet which increases its gravitational pull on other planets. I also added the delete object button in this menu to make it easy to remove specific objects from the scene.

a

Demo for the project

What I Learned

In this project I learned how to apply real life theories and formulas into code. I also got to further my knowledge in UI programming with the edit menu. In the future I want to be able to create more tools similar to the edit menu to help designers and artists in the game development process.

Contact Me

jeffreypopek@gmail.com