Double Precision Vector3

Hello,

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:

https://github.com/kohlditz/vector3d

6 Likes

thanks! I might need this for an upcoming simulation project

How do I go about incorperating these files into unity?

Also, does it circumvent the float precision problem in the inspector?

Make new scripts in Unity, then copy and paste.

No, since these are custom structs and therefore can’t be used in the inspector.

–Eric

Do they need to be added to an empty gameobject or can they just be referenced in mono?

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. :=)

You don’t attach the script to anything, you just have it in your project.

–Eric

Thanks. Where I can see the changes ? (And same problem ingame)
http://img95.xooimage.com/files/f/4/b/sans-titre-421a7a8.jpg

There aren’t any changes; it doesn’t affect the way Unity works at all. It’s a custom struct.

–Eric

Ah okay thanks. I understand now. (Sorry, I’m french. :3)
And now I see Vector3d I didn’t see it before, I know now.

Thanks for making that publicly available. However I’m curious - How do you plan to get around the problem of physics precision in your game?

curious: what’s the point? (if you’ll excuse the pun :wink:

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…

Awesome, thank you.

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 :slight_smile:

Same here, thanks a bunch! Should help with the space sim greatly. :slight_smile:

Cheers!

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?

1 Like

So I just need to replace Vector3 , with Vector3d ? Could you post some example scene ? ( Even simple moving Cube )

Sorry , I am graphics designer , not programmer .

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.

–Eric

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.

3 Likes

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?