Tuesday, February 17, 2015

Solar System Simulation

My first game physics project was to create a solar system. This is a simulation of our solar system including the sun, 8 planets and the earths moon. Here is a video of the finished product.


In order to create this the first step was to create a physics system. The first part of this is just a basic physics object. I used euler physics for moving objects to make the calculations simpler. This works but it does leave inaccuracy that can affect the simulation. After adding the physics object it was important to add forces. The way I did this was have force generators, in this case a gravity force generator, that would be registered with each object pair. In this system each planet is registered with all the other planets. This allows gravity to affect everything the way we would expect. Once this system was done I needed to figure out the actual values I would use to setup my planets.

I used the precise orbital speed equation to figure out the planets initial velocity at the perihelion. I also looked up the values for each of the planets perihelion and placed the planets at those distances in AU. These calculations worked reasonably well for the sun and 8 planets but unfortunately this was not the case for the moon.

At first I thought that looking up the initial velocity of the moon would work. Later I figured out that it would need to be the combination of the velocity of the moon and the earth because the value I had looked up was relative to the earth and not the sun. Even this value did not work as expected, the moon would constantly get further away from the earth. This could be due to various inconsistencies within the system that were not easy to fix. Because of this I just played with the numbers until I got a moon that orbited reasonably around the earth. The values I have now allow it to orbit around the earth for a good amount of time but eventually it will still leave orbit.

Another challenge was choosing the sizes for all of the planets. What I ended up doing was having the sun be way smaller then it would be and have all of the other planets be relative to an arbitrary size for the earth. This was the only way the planets could be viewed in relative sizes and still us AU for distance. This allowed me to setup my camera to view all of the planets while still keeping some relativity. There is an issues with the moon, however, because it is so close to the earth it appears to be inside the earth because of the scale I used. This scale was not a perfect solution but I think it was ideal in showing off what I wanted to show off.