As I have mentioned in previous post, I am creating large scale space trading game. I do not plan to recreate realistic distances between planets, as this does not add anything to gameplay, but this does not mean, that space is small. Large space, requires large coordinate system, but float has limited precision. Off course I knew that, just didn’t know it will hit me so fast.
So, let’s look at float. In theory it can represent very large or very small numbers, and it really can. Just not all at once. We can safely make calculations within 7 powers of 10. This looks like a very large number. Coordinates from -10 000 000 to 10 000 000 on paper look like something we can do without lose of precision. For most games one unit of mesure is 1 meter. It is simpler this way. For space game with large ships (up to dreadnought) 1 meter is a bit to low. We can use 10 or even 100m as one unit. As I will use very large ships, I will be using 100m as unit. But this means, that 0.01 is one meter, and to be honest, we have to be able to accelerate slower than by 1 meter in 1/50th of second (which is standard Unity “fixedTime”). We will walk fine line with 0.001 as our reference point of precision. There is one more bit. Apart from movement calculations, there are some visual calculations, that require precision, for example shadow calculations. So, let us take this precision and see what we have left from our 20Mx20M square.
10 000 000 moved by 3 spaces gives us 10 000. 000. Yeah, we have only 10k left. That is still about 1M meters (100 x 10k), so around 1000km. 1000km in space is not that far. It may be enough to simulate single point in space like space station and it’s surroundings, but It will not allow to make whole solar system, where you can fly around. Range from sun to earth is about 150M km, and we can simulate 1K km.
Ideas:
Go double
This will make all calculations slower, may still not be enough for larger systems, and what is most important, Unity does not support it. – REJECTED
Create own coordinate system
This will make calculations slower, may require, to write some math operations for it, and Unity will still not support it.- REJECTED
Teleport player to special map
Well, many games do it, I wanted this world to be whole, not just a lot of maps player can visit. That was general assumption. – REJECTED
Fake it!
Well, if you can not make it, fake it. And so I did. Whole game is layered. There is “Local Space”, there is “System Space” and there is galaxy. Local space is always located somewhere in global space. If you get to local space boundary it will move in global space, and will move some objects, and unload other. Player operates in relatively limited space, and this 1k km space is enough for local play, but if player want’s to fly further, it will be possible. It will be even possible to fly from one planet to another without fast travel. As we have player in local space, all we have to do, is add objects from global space. For that we will render them using separate camera and make them look, like they are there. If object gets close enough it will be moved from global space to local space. This way it will be possible to die burned by sun, or crushed on planet. Planet landings are not part of this game. There is one catch. Even if we say, that 1 unit is not 100m, but 100km, we get maximum of +-1M km. I could change it to larger scale, but this creates synchronization problems between local and global space. I could add another layer of illusion, and instead of 2 layers have 3, but this would add unnecessary complexity. Instead, I have decided, that for the purpose of this game it is enough. It looks good, feels right from viewer perspective, it does not really matter as far as game goes.
Time
There is one more little detail. When we move from one system to another, and get back some time later, it would be nice if planets in this system moved just right amount. But it means, that keeping planet position as Vector3 will give us nothing. Instead of that, we will be keeping rotation Axis, orbit range from center, position of center or center object handle, start orbit position (in degrees), and orbit speed (deg/min). This way, we will be able to tell where exactly object should be located, and we will still be able to use relatively easy method of updating position in current solar system.