I’m trying to draw an orbit line of a space ship around a planet using lineRenderer. I’m not using Unity physics, but rather my own, making it easier for me to predict/simulate paths/orbits. The problem I’m having, as far as I am aware, has to do with floating point inaccuracies. Because my ship is small, and my planet is obviously huge in comparison, an insignificant error value near the start of my trajectory line “dominoes” down the line causing a randomly, significant error in destination. The math is correct because I use the same fiction to move my ship as I do to simulate where it is going. So my question is, what is the common way of making a trajectory line that requires long distances and high precision?
I’m not using Unity physics, but
rather my own
Well that means “your own” way is the problem. floating point math is 100% deterministic. If there are any differences between two runs it depends on you using not the same input. The most common issue is deltaTime which is never the same between two runs. It’s not clear what exactly you are simulating. However you should keep in mind that deltaTime can only compensate linear changes over time. Any non linear change can’t be simply scaled by deltaTime. To get the best fit for quadratic changes (i.e. constant acceleration → linear velocity change → quadratic position change) is to apply half the old velocity and half of the new velocity.
However any other non-linear motion can’t be simply “fixed” like that. That means if you apply changing forces (not constant like Newton’s gravity) the resulting velocity won’t be changed linearly and the resulting motion would not be linear either.
That’s the main reason why most physics systems work with a constant deltaTime value to ensure the same results, even they are not “correct”. However to correctly simulate gravity with a time discrete simulation can be quite tricky since calculating correct time discrete values highly depends on the derivatives of all involved formulas. That’s a main problem with time discrete simulations as they usually assume the system does not change in between time steps, only exactly at each step. However most processes in physics are continous. So you would need the limit of your calculations with deltaTime goes towards 0.
For reference an SO question about that problem