More than 24 Layer solution

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.

  1. Do you need to simulate them all the same time? Maybe you could just render all planets together in regular space together and only when you get closer to one of them you put it on a separate layer and start simulating in local space.
  2. If you have objects orbiting planets, but they are relatively close to the planets, then in theory you could just put far enough, so the object do not collide. Of course you still have to solve the rendering problem somehow…