- Home /
Y value in Vector3 and Vector3.y not the same
I don't get why my Vector3.y and when I print the vector3 is not the same the y values are not the same. Here is a picture of the output: underlined in blue is the vector3.y and in red the y value of the whole vetor3. Each row is the same vector I just underlined for clarity. In the code I never modify this vector in any way nor the y value. I just use it to check for things in if statements. It's really messing me up that these values are not the same. I understand they are close but why is there a difference at all? How can I get it to give me 0.0 instead of 0.00000000000000009432...?
You can't, it's just how computers work. It's how floats work. (Indeed, it's how any engineering works, everything has an error when you're building bridges, etc.)
For deep information on how floats work in computing, read-up on a site like stackoverflow or wikipedia. This site is really just for Unity specific questions, not general software engineering questions.
Answer by cagezero · May 06, 2013 at 02:46 PM
For a discussion on floating point precision check out this answer:
http://answers.unity3d.com/questions/50187/floating-point-accuracy-weirdness.html
For understanding how to deal with the difference between the printed value and the actual value look at this answer:
http://answers.unity3d.com/questions/167622/vector3tostring.html
Your answer
Follow this Question
Related Questions
Slerp to make the right/left side face another object 2 Answers
Is it posible to attach a crosshair to an image in vuforia? 0 Answers
assigning vector 3 through scene positioning 0 Answers
How can I assign an Array of Vector3 while seeing and editing the values in the Scene? 0 Answers
FPS Controller Confusion... 0 Answers