- Home /
Unity 3D world space coordinate bounds?
What is the minimum/maximum x,y,z values that can be used for unity 3d coordinate system?
In a 3d space game I want to know when a object will fly past (exceed) the maximum coordinate that unity can support?
I am consider a multi-star system game. In order to accomodate stars seperated by large space that then have planets around them also seperated by large space and then small space ships flying around I want to know how much "territory" I have to work with.
Thanks for help!
Answer by Wolfram · Aug 16, 2010 at 03:46 PM
You need to be very careful about choosing an appropriate scale for your star systems. Unity as a game engine uses only single-precision 'float', so you are very limited in what you can do.
'float' can distinguish only around 7 digits, so it will already have a very hard time distinguishing between 1000000.0 and 1000001.0, small motion will become very jerky, or not recognized at all, etc.
The overall scale that floats can handle goest to about 1e38 - but you don't want to use numbers that large, since you will run into several problems at various points in the engine - starting with camera clipping planes, etc, not to mention the physics simulation algorithms.
You probably need to think about other solutions, like adaptively changing the scale depending on whether you are around a planet, in interplanetary space, or in interstellar space. Or making actual scene switches when switching between interstellar view and orbit view etc. Or simply use smaller scale differences - forget about "realistic" scales, like trying to represent a 2 meter human in a spaceship orbiting a 1.2e7 meter planet at a distance of 1.5e11 meter of its star (these are realitic numbers for Earth+Sun, for example) - it just won't work, even with double precision floats.
EDIT: one more thing, because of the precision limits, any computation will get more imprecise, as you move more and more away from the origin (0/0/0), so you should try to keep your camera and/or player/point-of-interest always around the origin, instead of letting it travel to vast distances. It might be better to move the stars/planets around and keep the player fixed, instead of the other way round. Test this for yourself: create a unity cube, place it at (100000/0/0), and press 'f' in the SceneView to zoom to the cube. When you now move the scene view around the cube you's see it is getting very jerky, and the rendering of the collider does no longer match the cube faces at all times.
The Edit you've given is how I was thinking about it, but I also thought of another (perhaps weirder) solution.
Chunk the world into cubes. When the camera passes across a cube boundary, increment your 3D cube index so that you can keep a track of base "universe space".
Everything inside a cube is within a more reasonable floating point range, i.e. -100.0f..100.0f for X Y and Z.
This might reduce the amount of repositioning overhead you'd have to do - you would only have to reposition objects relative to the player when passing over the cube boundaries. It might be slightly more efficient.
That sounds like a smarter approach to my suggestion of "making actual scene switches", i.e., distributing these space sectors in different Unity scenes - but maybe one doesn't want to switch scenes all the time. Although this could be nicely combined with some kind of "entering hyperspace" cutscene animation. With your idea, you'd have everything together, you just need to take care of what your camera sees "beyond" such a cube, and where the "unused" cubes are placed so that the camera doesn't see them (which is easy: beyond the far clipping plane).
Some great info and suggestions. Particularly the move everything else rather than the player gameobject. Thanks!
I am currently build a space game and I have to say I am finding the limits a lot closer than that. I am getting limits around 200k.
@Snownebula: $$anonymous$$aybe you didn't really understand that answer. There are no actual limits. As soon as the position is greater than 1.0 or smaller than -1.0 you will loose precision. It's a floating point number. What precision is "enough" depends on your scale.
A floating point number is stored as a binary number. Whenever your number before the decimal point requires 1 bit more, you will loose one at the other end. That's what the "floating point" actually does.
For space games it's most the time necessary to "chunk" your world. Aubrey Hesselgren's solution is the most common one i would say.
Your answer
Follow this Question
Related Questions
3D rotation in sphere cartesian coordinates 0 Answers
Adjusting camera so the whole level is visible 0 Answers
Simple example bound box or get the top position gameobject 1 Answer
Fix a GUI's position relative to a 3D object 1 Answer
My ingame avatar's worldspace does not coincide with other objects 1 Answer