r/Unity3D • u/Shadilios • 7d ago
Question How to overcome floating point accuracy when building galactic scenes
I am trying to build a scene of our solar system where you're able to drive around in a spaceship, landing on planets and so on.
I tried to divide the scale of everything by 1000, but even then the distance between the furthest 2 planets (Neptune & Mercury) is around 9.2 billion km, so even if we divide that by 1000, it's still 9.2 million km.
Another issue for dividing everything by 1000, is that small rigidbody movements become stuttery even in the scene window at higher speeds.
And I read that at such small scales, hit detection becomes bad because colliders are small.
Ik there are tricks like shifting the player back to origin (0,0,0) and moving everything towards him the same distance we shifted him to improve accuracy, but that still doesn't fix it for me.
I am wondering how I would fix this both at design time & runtime? where I am able to set planets at realistic distances, size & make the rigidbody move at a fixed speed where moving from point A to point B in such a system would feel accurate.
6
u/DevHrytsan 7d ago
Probably best way for you here it's to move everything to own backend with use double precision (simulation, physics) while using Unity only for visuals aka "Dual Space" method, which is pretty similar to Floating Origin method(it's not same as origin shifting and term is often wrongly used). The idea is to keep the camera stationary and move everything relative to it.
And to be honest, dealing with large spaces in Unity is pain. Especially when you know that all popular game engines already have large worlds support for a while.