vector.z returns 3.0616168005906749e-17 every time i try to use it, but when
i use Debug.Log on the vector itself (not the z value), it returns 0, which is what it should be.
here is the code that returns 0:
// (-0.5, 0.5, 0)
foreach (Vector3 x in mesh.vertices) Debug.Log(x.ToString());
// (-0.5, 0.5, 3.0616168005906749e-17)
foreach (Vector3 x in mesh.vertices) Debug.Log(x.z.ToString());
It is, specifically, 0.000000000000000030616168005906749.
Yes, that’s 17 zeroes prior to the number, since “3” itself is 3e0.
To address your observation first, the “ToString()” (with no arguments) functionality assigned to Unity’s Vector3 struct displays very few decimal places (maybe even just 1 digit?), whereas the default for a float is many more. If you wrote the line as…
Debug.Log(x.ToString("F16"));
… then it would probably display the same value on the Z-axis, rather than rounding the displayed value to 0.
The value not being *exactly*0, in this case, is likely the result of floating point imprecision. Considering how tiny a value this is, it's effectively zero (or, at least, such a small value as to be completely insignificant), and is a side effect of the fundamental way in which floating point numbers are held in memory.
They can’t represent every value within their range (with a maximum value of approximately [3.4028235 * 1038], or [3.4028235e38] for a 32-bit floating point, you would essentially have 30 zeroes after those digits that can’t be anything else), but they come so close that the difference is insignificant.
I don’t have a good answer for why you’re not getting exactly 0, but just an FYI, 3.0616168005906749e-17 is scientific notation equal to 0.000000000000000030616168005906749 not 3.
That’s pretty damn close to 0.
The problem was that i forgot about the size of the quad (the shape that the vertices should produce),
So, no. Nothing is wrong here, i still don’t know why Debug.log prints out 0, but at least it works now.