N-Body Orbit Simulator in Luau

I have a video that explains this better, although I’m unsure if I’m allowed to post outside links here (just youtube).

Pseudo-Realtime N-Body Orbital Integrator

Alright, I’ll try to keep this short. I took a jab at coding an orbit simulator. After playing around with patched conics, I decided to use an N-Body system instead. This yielded me more flexibility. If you are familiar with KSP, I do not use any spheres of influence (Any encounters are purely symbolic, there is no ‘handshake’ between celestial bodies). Instead, I calculate the gravity gradient using N-Body physics. This approach allows me to simulate a variety of celestial mechanics phenomena, such as Lagrange points and constant forces acting on a projectile, like solar pressure. Interestingly, this also supports long burns. To make the simulation more user-friendly, I’ve added a time compression feature. This is particularly useful for long orbits, where waiting three days to approach a target is impractical.

Here, I have an object that I put into a trans-lunar injection. The green track is a maneuver I’ve set up right before the encounter (I say encounter, but once again, there is no sphere of influence). This maneuver track gets me in a return trajectory back to earth. I’m still working on refining the user interface and trajectory representation, so any feedback would be greatly appreciated.



Lagrange points!!!

All distances you see here are distances from point masses, not altitude. Also, that little panel on the bottom right is unnecessary, as I’m no longer using a patched conics model. While it was cool playing with Keplerian orbital elements, they are really unreliable at highly eccentric orbits. In fact, they were a burden on server processing when solving Kepler’s equation.


Lunar capture burn!

It’s buggy, it’s clunky on orbit baking, but other than that it runs smooth. Oh, yeah. By pseudo-realtime, I mean I bake the orbits whenever an unpredicted change in velocity is detected. I tried realtime rendering, and boy was it unreliable and jank.

Edit: I forgot to mention, the mean elapsed time in the bottom right is bugged. It will occasionally read 3 months time-of-flight for a single orbit. It’s just a read error on the serverside.

12 Likes

Can we play this game? I would really love to mess around in this.

2 Likes

Not yet, but that’s the idea. I’ve got a few more things I want to do before I want to put my name on this. I’ll let you know!

2 Likes

Here’s an example of an object in TLI. Once again, no spheres of influence. Just gravity gradients. Also, the last bit is just me trying to reduce the time-until-burn before I figure it’s futile… oops.

2 Likes

This looks like an awesome piece of work

1 Like

I’ve released a public alpha of my current draft. You can check it out here!

This is very sick dude! Very excited to play this game.

1 Like

Thanks! I want to make sure that the simulation runs well before I pursue playability, but it’s planned.

Any feedback would be great.

Okay, most of my reviews are brutally honest so I’m gonna do the same for this game.

Pros :

  • The graphics and planets look sick!
  • The simulation runs very smoothly
  • Playability is average and decent at the same time.
  • Camera movement is very smooth just how I would want it to be.

Cons :

  • Some bugs like when speeding up to 10000x speed the simulation breaks.
2 Likes