#It should not ever reach it, and I
1 messages · Page 1 of 1 (latest)
Gotcha thanks. Just wanted to make sure that I understood that math behind it.
So if I understand correctly vector3 is float based and given that floats themselves offer 32 bit precision the number can only be so precise.
Out of curiosity, would you happen to know why there wouldn't be a "toggle" to switch Vector3 to double?
*My assumption is that it would be there if it could; even in the case where Unity decided that it's unnecessary/inefficient I would think they would at least have the option there for those who want it. Did Unity just not bother or is there another obstacle in the way (hardware/software). *
(Super new to programming/Unity sorry if these are basic questions)
The issue isnt related to it being floats or doubles really. The issue is that your code is constantly moving closer to the object by a factor of 50%. Consider this in 1D, you are at 0 and an object is at 10. On the first move you go to 5, then 7.5, then 8.75, and the distance keeps closing in to eventually reach 9.99...
There is no way you can visually see a difference from 9.99 and 10.
Floats simply use less space than a double, that's why they are chosen. You do not need doubles
Got it.
The thing about the doubles was more of a side question not related to my code.
Personally I wouldn't even know what to do with double precision, but I'm wondering (aside from finding it unnecessary), if Unity has other obstacles that would not allow the implementation of such feature? (i.e/ Wouldn't they add it for the fringe minority that would want it if it was as simple as making a toggle?)
^Like would adding such a toggle affect performance for people who don't have it enabled? It doesn't seem like it would be that big of a feature to add but I can only assume I'm missing something.
Theres just no point to really having it. If you wanted, its trivial to make one yourself. Just have a struct with 3 public doubles inside. The thing is, doubles are mostly useless.
The literal only case where I use it right now, is because I use System.Random for deterministic results
Having it as a toggle would actually be a LOT worse yes. Having it as a separate struct entirely wouldnt affect performance
When you assign a struct, you are copying the data. It would be a difference of copying 3 floats vs copying 3 floats and 3 doubles everytime just because of the toggle.
A float is 4 bytes and double is 8. So it would go from (3 floats) 12 bytes to (3 floats + 3 doubles) 36 bytes
Sorry by toggle I mean having the option to have vector3 by default use a double structure if that makes sense.
in this case would you still be able to interact with the unity classes?
But no I guess your right in that it has such little use case even if it was possible to make that little switch, the demand for it doesn't really justify implementing the feature
Any option would still require all the data to be stored on the struct, which makes it way worse
You make your own classes all the time, you just using UnityEngine and you can do what you want
Though still I'd advise against making this vector3 double class. You will need conversions to be able to use it directly as a position for example, since position is a regular Vector3. This conversion will lose you information if you ever read it back from the transform.position because doubles have 8 bytes and floats have 4.
oh okok, yeah that what I thinking when I asked about interacting with the default unity classes with your own double classes*
probably never gonna use this but was just interested in how it all works
Yea it's still possible, but not really useful to do
It's similar to how Vector3Int works
There is a conversion that let's you directly use it where it expects a Vector3
ahhh okay okay