A project to implement learnt design patterns


by: Vandit Narain Tyagi

The idea.

It started as an idea that a player can move around a 2D planet and interact with objects which are physics-based. And the player can launch objects from the ground that can enter the upper atmosphere of the planet to become satellites.


So I started putting things together in Unity. Made a model for the character, the planets, wrote some scripts, and set this up:


Although things were working quite well, it was a bit tricky to keep the objects in orbit. The first thing I looked to implement was the Gravity equation from Newton. I quickly realized that even though, universally, the equation works quite well in our massive universe where bodies have celestial masses, it's not for my tiny 2D universe. 

So I set out to design my own equations for managing the states of the objects. I set up a basic Interface for objects to become satellites and created a rough script map.

Then, I also created a basic blueprint of different states an object can be based on its velocity and place in the 2D universe.


For eg., There are two objects, A and B with velocities Va and Vb respectively. When the objects enter the area between R1 and R2, it performs a check on the direction of the movement. If the direction vector lies within an angle range of the normal of a straight line from the planet center to the object center at that point, it becomes a satellite and starts to follow that same normal around the planet. Otherwise, it falls freely to the surface of the planet. Check the video below for the demonstration of the same.


After achieving this, I implemented transitions between states based on the current state, velocity, and whether the object is in the vicinity of a planet. I also used the same Satellite Interface to make the planets revolve around a stationary star. 

For visual purposes, I added trails on objects and planets. Planets have their trails all the time and the objects only show their trail when they enter an atmosphere of a planet. After all this, I set up a new scene in unity with lots of objects, gave them different initial velocities, some planets, also with initial velocity and speeds, and put together a build of the simulation. The build is a windows executable file, which can be downloaded from the project's main page. The following video shows how the simulation looks and works. 

Get 2D Star system Simulator

Leave a comment

Log in with itch.io to leave a comment.