Nice auto pilot! Very basic, but works well enough.<p>In the real world, you would derive physics equations (acceleration -> velocity -> position), add constraints and then solve everything to obtain an optimal trajectory (mostly in term of fuel, but you can add other constraints too, for ex due to radar-ground or Antenna-Earth visibility). I wrote a blog post about Apollo's algorithm: <a href="https://blog.nodraak.fr/2020/12/aerospace-sim-2-guidance-law/" rel="nofollow">https://blog.nodraak.fr/2020/12/aerospace-sim-2-guidance-law...</a> (Described in the second section ; the first section is about a naive algorithm similar to yours that in the end did not work as well as I wanted).<p>Also, thanks for the code, I wanted to do the same, but lost motivation when I could not really expose in a satisfying way the internal state out of these JS modules (it's not complicated in the end, but I'm simply not a frontend dev ; and I wanted to avoid forking and monkey patching everything and simply adding some JS code throught the console or something).