- Home /
Losing float precision when adding to Vector3
Hey Unity'ers :) I've got a bit of a strange problem - I've got 3 floats which I'm adding to a Vector3. They're originally initialised to 0f,0f,0f, and are then overwritten when new data comes in.
when any of the 3 values change, the Vector3 gets rebuilt; however, it seems to lose all precision, down to 0 decimal place, whenever added into the Vector3 struct. This means that 20.45f turn into 2045f.
This does not happen when building and running the game on my own computer. This only happens when building the game and running on another computer. How does this happen?
Answer by toddisarockstar · Dec 29, 2018 at 04:55 PM
vector3 is just a class of three floats so you are probobly not loosing any precition in your game. my guess is that your string display in a debug or print statement is just shortened by unity for easier reading. but I would guess that the actual floats are safe.
I use the float to position my gameObject and the gameObject indeed stands at 2045 ins$$anonymous$$d of 20.45 (When game is running on other computers except $$anonymous$$e)
I agree with @toddisarockstar, in general. However, given your description that it is different on other computers, I suspect you are relying on some default formatting that is different. $$anonymous$$aybe because of a lack of floating-point processor on the other system? Or is the other system in a different language? ($$anonymous$$g., yours is English and there is is not?)
To be sure, always format your string specifically to make sure you get the expected output (rather than passing variables to some function to let the system display them).
It's hard to say more without seeing a snippet of your code. If you want to post that, I'd be happy to have another look.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Vector3 using Doubles Instead of Floats 2 Answers
Convert double to float for Vector3 1 Answer
maximum distance from origin (float precision) 1 Answer
CharacterController.Move precision 1 Answer