- Home /
Space unit size
Hi,
I'm making a space game, and currently I have that one unit in unity is one kilometre. So some objects can have (or will have) an x, y or z value of many thousand, if not millions. So I was wondering, how big can a world become, without getting problems with rounding of numbers and such. Can I keep the 1 unit = 1 kilometre, or would it be wise to change it to 1 unit = 100 or 1000 kilometre or something?
I have a ship, small cruiser, like the Enterprise (or something), but also spacestations, meteorites, ... So my unit's can't be too big either, otherwise the spaceship would have to be too small.
What are your thoughts on this?
Thanks a lot!
-Pablo
Answer by whydoidoit · Jul 26, 2012 at 01:47 PM
I'd say you are definitely going to have a problem, floats just aren't very precise especially when they get big (or small). If you are going to model the whole of space then you are probably going to have to maintain the actual positions using a much more accurate variable and map that down to real positions when the objects are closer together. You should probably consider storing world coordinates in doubles (or indeed Decimals - I've never tried in Unity, but they are a feature of .NET) then have a script that sets the position of the objects to camera coordinates when they are in range, effectively keeping the camera static and moving the world past it.
So unity uses floats for the position... Is it possible to make it store it as doubles? I'm not going to make the whole of space, just parts of it, but still those parts are pretty big :P
No it isn't - only using the method I suggest here - mapping your own coordinates onto the Unity coordinate system.
I'm trying this now, and it works well, though there is one problem. Any ideas how I can position my stuff in the editor itself, beyond the range of a float?
$$anonymous$$ark you script as ExecuteInEdit$$anonymous$$ode and it will also happen during the editor sessions. You could check for Application.IsPlaying being false and then reverse the operation too - setting your world/space coordinates equal to the editor ones.
Yea, was trying that. And that works, though the IsPlaying stuff isn't really useful, it just show you the coordinates twice then... Now I just set the space coordinates to my editor coordinates on Awake, en then move everything around my ship. That works, my ship is now always on 0,0,0, and everything else moves. I'm still playing around with it but it seems very promissing :D
Answer by Kryptos · Jul 26, 2012 at 02:48 PM
One technique that is a bit counter-intuitive is to make the world move around the character (instead of the character moving in the world), so that the character stays at position (0,0,0) where the maximum precision can be achieved.
Far away object will suffer precision problem, but since they are far away it is not important.
One drawback of this technique is that it is not possible to mark any object as static. In some cases it is a critical drawback that makes it impracticable.
To do so, you need to put all objects (except your player and camera) under a common parent node (that we will call "root" node). Instead of moving the character when responding to player input, you move that node in the opposite direction (same with rotation).
Now if your world is very big, it is unfeasible to edit a scene where objects are one Light-year distant from each other. What you can do is make some prefab of each space area. Store in a list the real position of theses areas. When the character approaches the position of one area, instantiate the prefab. When it moves away, destroy the instantiated prefab.
Your first solution looks like the same one $$anonymous$$ike gave, or am I missing something? The second seems a good one too, though I won't need that big a world. I think I'm going to go with the first one. So I'm accepting the answer of $$anonymous$$ike, since he was first, though thanks a lot to you too!
Your answer
Follow this Question
Related Questions
m/s "Meters" convert to au/s "Astronomical Units" 0 Answers
Can you download unity editor onto a USB device? 2 Answers
Space ship controls locking into place 1 Answer
Box Collider bounce causing rigidbody to change rotation -1 Answers
3d space scene tutorial? 0 Answers