It has been a minute since I last posted a devlog, and this is not it but it is coming soon, I promise. Today I want to talk about my gravity engine using Euler's method of gravity. The first step to this process is to make the planets, I just made a bunch of clones that all drew their position onto the screen with the pen extension. There is also another sprite the size of the screen that refreshes it every tick by stamping it onto the screen.
Next I gave each of the planets an initial velocity and mass scaling their size to that mass, you can't see it because the mass of the planets is too close but they are scaled with their mass. The amount that the velocity moves the planets is scaled by the global variable SIZE which also scales the planet size. I have it set to 1000 in this simulation. The result after a few seconds looks like this:
After this I setup a function that would make the planets be able to interact with each other's gravity. The way that It works is that each planet has a position in a list along with a mass in a list and this makes it so that the other planets are able to change their velocity depending on the other planets. I made it so that each planet every frame loops through this list and finds the distance to the planet that is selected and changes a sumXVel and sumYVel variable by the distance x / (d * mass) and the same thing for the y distance. At the end it changes the x and y velocities by the sum x and y divided by the total amount of planets. After a few seconds the effect looks like this:
In the end I also added some developer tools such as pausing, deleting planets, and most importantly creating planets. The way that the creation of the planet works is that first you are asked for the mass that you want, then whether or not gravity is on or not, then you find the position that you want then press space and It creates the planet. Anyway, thanks for reading this is my first article with pictures, hope you like them cause there is more to come and more below of the best pictures I got.
Y'all have no idea how long that last one took but I like it. Thanks for reading and have a great rest of your day :)









Top comments (2)
Also that final shot took 2 days to get into a stable orbit around a larger body
Sorry for the long wait y'all.