A downloadable project for Windows

An N-Body Gravity Simulation With Universe Expansion

The goal of this project was to create a basic gravity simulation toy that would visualize what effect scaling the space in the universe (expanding or shrinking the space) would have on 3D gravity particles inside. This is supposed to be broadly analogous to what galaxies experience with the expansion of the universe ripping them apart from each other.


When playing with the values, setting a high expansion rate, no local structures can form and all stars get ripped away from each other. I have colored particles that move away from the camera red, and move towards the camera blue in the gifs below.


Setting a negative expansion rate will cause the universe to shrink together until it collapses into a small point. For both cases of infinite shrinking and infinite growth, floating point limitations mean that they both break down at those extremes, but the broad behavior is still demonstrated.

The game has settings to control the strength of gravity, the expansion rate of the universe as well as the number of particles.

On moderate (but non zero) expansion rates, gravity and expansion battle each other. This results in larger structures breaking up or not forming, while smaller collections of a few particles are able to still be gravitationally bound together.

The gravity simulation is still fundamentally based on Newtonian gravity, and leverages Compute Shaders in Unity to calculate gravity attraction on the GPU at high speeds with large amounts of particles for the most part. No particles have collision. Players with lower-end computers are advised to turn off the Bloom VFX and Redshift FX, as those have noticeable performance overhead.

This physics visualizer toy was created as a final project for a Spring 2026 UCI Physics 20B cosmology class. The purpose of this project was to show possible end states for the universe given different rates of expansion of the universe, but it is worth noting that due to limited resources, the simulated universe is finite, and so cannot exhibit some of the cooler behavior accurately that an infinite (or much larger) universe would show under some extreme situations.


Controls:

WASD to move camera around

Scroll to zoom in/out

Press Q to toggle between the 3 camera mode options

Press Escape to open simulation & graphics settings menu


BGM Music Attribution:

Music: Binaural Sleep Vol. 5 Produced by Sascha Ende

Published 2 days ago
StatusPrototype
CategoryOther
PlatformsWindows
AuthorThe Pig Guy
GenreSimulation
Tags3D, galaxy, Gravity, Space, Space Sim, universe

Download

Download
GravitySim.zip 43 MB

Install instructions

Make sure to extract the zip folder before running the exe file to play.

Leave a comment

Log in with itch.io to leave a comment.