Hi everyone,
This question is pretty hefty but I really need to ask it.
I’m building a game at the moment, set in space, that requires each of its planets to be simulated simultaneously. Originally I wanted to have each planet as an orbiting object with the sun at the center, and have each entity simulated in realtime. Unfortunately this ran into issues at larger scales, due to floating point precision limitations.
In order to get the scale right, I’ve had to abstract the planets and solar system into two separate entities and treat each planet as the center of the scene (that is; place it at {0, 0, 0}).
In order to get this behaving correctly, preventing the entities of each planet from colliding with and interacting with one-another, each planet has its own layer that it and its children all sit on. The layers are set in the physics settings to not collide with each other, meaning that entities from any given planet can only interact with entities at the same planet. This means that when I want to switch to another planet, I switch the target layer of the camera and the appropriate planet pops into view.
This has its limitations, however. Whilst it works perfectly for up to 24 planets, it simply isn’t possible to get it to work for any more than this, because Unity doesn’t make allowances for more than 32 physics layers. With 8 already chewed up by the engine, it’s not possible to get any more than the 24 other layers, in turn meaning that I can only have 24 planetary bodies.
My question is; Is there a workaround for this? And if not; How else could I separate the planetary bodies such that they are located at the origin (and avoid floating point precision problems), update and behave as normal, and don’t collide with or interact with one-another.
Regards, Mav.