Devlog #4: neutron stars, cleaner orbits, and cosmic nonsense
this update started as “fix the math a little.”
then neutron stars got involved.
after the last devlog, the sim already had Barnes-Hut gravity, spatial hashing, black holes, white holes, and supernovas. it could throw hundreds of bodies around, but the math needed to feel less cursed. so first i split the project up: the main loop, renderer, and simulation code now live in separate files. boring maintenance, but very worth it. changing gravity code is much nicer when it is not buried inside the draw loop.
then i changed the integrator.
before, bodies used a simpler velocity/position update. now the sim uses velocity Verlet. it calculates acceleration, moves bodies using current velocity plus half the acceleration term, recalculates acceleration, then updates velocity using the average. the result is better orbit behavior and less fake energy drift.
Barnes-Hut got a correctness fix too. a body could be inside a quadtree node that still got approximated as a far-away cluster, which meant it could get a tiny pull from a group containing itself. now internal nodes containing the target body are never approximated. the tree has to recurse deeper, so the gravity math is cleaner.
now the fun part: neutron stars.
neutron stars are compact, bright, and violent. they have a tiny fixed radius, pulse with blue-white halos, and shoot narrow rotating beams like little cosmic lighthouses. they are also dense enough to rip apart nearby bodies.
i added tidal disruption: when a normal body passes inside a neutron star’s Roche-like limit, it gets shredded into hot debris instead of simply merging. the neutron star absorbs some of the mass, a shock ring flashes outward, and particles spray away with the victim’s old velocity mixed into the blast. it looks nasty in the exact way i wanted.
supernovas now tie into that properly. before, the remnant logic was too simple. now it works like this:
- below 2000 mass: the star blows apart and leaves no compact remnant
- 2000 to 2599 mass: it collapses into a neutron star
- 2600+ mass: it collapses into a black hole
so a massive star can explode and leave behind a neutron star, but only in the right range. if it is too massive, it becomes a black hole instead.
the emergent sequences are getting really good now. binary stars spiral together, merge, cross the supernova threshold, explode, and leave a neutron star in the debris. then that neutron star starts tearing through nearby bodies, throwing off little streams of glowing fragments. sometimes a white hole shoves the whole cloud sideways. sometimes a black hole eats the aftermath. none of this is scripted. it just happens because the rules are finally interacting.
with collisions off, the screen turns into these huge braided orbit paintings. with collisions on, it becomes a machine for making disasters.
next i want to make it easier to capture the good moments: probably a hide-UI key, better presets, and maybe a follow-cam so one chaotic object can become the main character.
thanks for reading :)