- Home /
Long-distance physics
Good day.
We're doing a procedural space game with newtonian physics, and scale is beginning to be a problem. Most of you will be aware of how Unity's single-precision coordinate system causes objects to jitter when they're far away from the (0,0,0) position - we encounter that one primarily with compound colliders using a rigidbody, which tend to look completely ridiculous at more than 1000km away from the world centre.
We're now planning to write our own simplified and abstracted physics simulation for faraway objects, but we're still reliant on various Unity features. I would like to know which of them we can still use at those distances, and which simply won't work anymore when you use the on something that's ten million metres away.
Raycasts - can I still rely on them, or will they give me false negatives/positives? Rigidbodies - compound colliders jitter a lot out there, but are their rigidbodies' movements still physically correct? Colliders - does collision detection still work that far out?
Answers to those three as well as general input related to the issue is greatly appreciated.
Scale is arbitrary. There is no difference in Unity between a world where 10 units is a meter and a word where 10 units is a kilometer except for adjusting things like the force of gravity.
Do you really need such dynamic range or can you just adjust your scale?
Doesn't work, I'm afraid. Floating point precision suffers from distance as much as from scale reduction.
That then would mean the answer to "do you really need such dynamic range" would be yes.
The next question is... why? You would have to have relatively small objects moving incredibly quickly to cover those sorts of distances....
Small objects moving fast: Bullets as small as 10mm being fired at velocities ranging from 500m/s (short-barrelled conventional guns) to upwards of 3000m/s (railguns/coilguns). Spacecraft and missiles of various sizes with plenty of fuel being able to accelerate until they run dry, with no air resistance to slow them.
And there's bigger, slower stuff too, which just happens at long distances - the game's set on a pretty large scale, with stuff happening in multiple places simultaneously.
It may be worth checking out how $$anonymous$$erbal Space Program approaches these kinds of issues. Their developer blog has a number of articles about using multiple coordinate spaces to get precision where they need it.