I’m making a space game and needed higher precision than Vector3 to represent the vasty nothingness of space so decompiled Unity Vector3, Vector2 and Mathf and converted them to double precision. Most methods were relatively straightforward to convert (they were converting floats to doubles internally to do the math). There’s a few cases where the method called an internal Unity function, in those cases I’ve wrapped the original function.
I checked with Unity if it was okay to distribute this and they said it was, so if you need higher precision you can grab the files from here:
Hey, this is a very big interessing script.
But now, I don’t know where I need to add the script. I’ve tested in camera (also tried the moving part), and it say “Can’t add script behaviour Vector3d. The script needs to derive from MonoBehaviour !”. So, I guess it’s because of “using System”. But what now ? :s. Thanks in advance. :=)
curious: what’s the point? (if you’ll excuse the pun
won’t the resulting calcs be cast back to float in the bowels of the engine anyway? until UT uses doubles internally, this will always be an issue AFAIK…
Do you have a suggestion on approach for implementation? I.e. Referencing the double precision coordinates to the float precision that Unity Supports? So when getting to x, switch to a local precision?
Man, you’re great! Double math it is what I need! Now I’m learning Unity and C# (very basicaly, started few days ago), but far away I have planning to create space sim. It will help me a lot, I hope
Just one more thing though. What about rotations? Quaternion doesn’t seem to be working with doubles, while conversing from double to float just to make a rotation wit Q. doesn’t sound great either. Any thoughts?
It’s really only of use to programmers. You can’t just replace Vector3 with Vector3d since everything in Unity itself uses Vector3 and that can’t be changed. Only your own code can use Vector3d.
One example would be giving your GameObjects something like a “dpTransform” which stores the position with double precision.
Now, instead of manipulating the transform directly, you would always manipulate the dpTransform which, after it gets manipulated, updates the transform.
That way you’d prevent data-loss when something happens very far away. Sure, the engine would still give you problems, but your logic would stay reliable. The dpTransform would store where the GameObject is supposed to be.
Example situation where this would come handy:
Simulation very far away: Move GameObject x 10 cm to the right.
Problem: You’re so far away that movement happens in 1 m jumps.
Solution: Whenever the player moves too far away from the center of the map, everything is moved so that the player is at the center again. Say you go forward, when going over a “border” everything is moved backwards so the stuff behind you looses precision, while the stuff in front you has its precision increased. How can this work? Our dpTransform stores the accurate data which is used to restore the transforms.
If there was no dpTransform we wouldn’t have been able to store the information that the GameObject is now 10 cm more to the right.
In my case,i have a transform.position for a game object.I am not able to use transform.position as it supports only Vecotr3 due to which i get an error.How do i rectify this?