Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

For the prediction of the trajectory you could do this:

The path of all your gravitational bodies should be deterministic. i.e. you could calculate them in advance for N frames and put their positions into a ring buffer. On every frame you then pull the positions out of this buffer and calculate the positions N frames into the future. In this way you only need additional memory but no additional CPU cycles.

For the player trajectory you can basically do the same thing as long as the thruster is not used. If the thruster is used you have to invalidate the ring buffer. As soon as the thruster is turned off you start calculating the trajectory again: maybe add 100 future frames on every frame, that should be possible as you only have to calculate it for one body (the player ship) and you can take all the gravitational information from the precomuted buffer for all celestial bodies.

(1 edit)

That sounds very viable, although it's going to be very frustrating to implement in javascript, which doesn't copy objects without a fight.  I like the fact that it's calculating the trajectory gradually, I actually think that could be a fun in-game upgrade factor.  Maybe your ship computer starts out being able to project 2 future frames per real frame, but you could upgrade that ratio in-game to much more so that you can more quickly see your projected trajectory.  This has the added benefit of gating a potential performance bottleneck behind optional upgrades, so even if I can't afford 100 frames / frame of prediction on some devices, it's only an issue if a user on a slow device chooses to heavily upgrade that particular stat.