A real-time N-body gravitational simulation built in Unity, designed to model orbital mechanics using classical Newtonian physics.
This project implements a multi-body physics solver to simulate the gravitational interactions between planets, moons, and custom celestial bodies. Rather than relying on hardcoded circular paths, bodies move and interact based on continuous force calculations.
The simulation handles:
-
Mutual Gravitational Forces: Computes real-time
$N$ -body interactions between all active bodies in the scene. - Euler Integration: Updates positions and velocities dynamically across physics timesteps.
-
Orbit Prediction: Renders projected trajectories ahead of time using a
LineRenderer. - Configurable Parameters: Allows tweaking mass, radius, initial velocity, and hierarchy setups (like moons inheriting parent velocities).
- Gravitational Solver: Applies Newton's law of universal gravitation across every active body per frame.
- Time Scaling: Adjust the
timeScaleparameter at runtime to speed up or slow down the simulation. - Lightweight Architecture: Runs natively in both the Unity Editor and final builds without external dependencies.
- Computes multi-step lookaheads to draw predicted paths.
- Toggle between highlighting individual body previews or rendering all orbits simultaneously.
- Custom color tinting for orbit trails to keep complex systems readable.
