Hi, I got a problem with a bunch of triangles I imported from blender. They are all supposed to be the same size. I’m trying to measure the vertices of each one with the following code:
var dist1 : float = Vector3.Distance(oldverts[0],oldverts[1]);
var dist2 : float = Vector3.Distance(oldverts[0],oldverts[2]);
var dist3 : float = Vector3.Distance(oldverts[1],oldverts[2]);
if (Mathf.Round(dist1*10)/10 == Mathf.Round(dist2*10)/10) {
test = (i.TransformPoint(oldverts[1]) + i.TransformPoint(oldverts[2])) / 2;
}
if (Mathf.Round(dist2*10)/10 == Mathf.Round(dist3*10)/10) {
test = (i.TransformPoint(oldverts[0]) + i.TransformPoint(oldverts[1])) / 2;
}
if (Mathf.Round(dist3*10)/10 == Mathf.Round(dist1*10)/10) {
test = (i.TransformPoint(oldverts[0]) + i.TransformPoint(oldverts[2])) / 2;
}
The problem is sometimes none of the if checks pass when one of them should always happen. Adjusting the rounding multiplier sometimes fixes it. Anyone have an idea how I can fix this please?
I just had the same error as reported here with comparisons. Thanks for the thread. Solution was that i had initialised the distance to compare with a var dist = 9999; and then always selected the smallest one. That meant that Distance was being converted to an integer every time… make sure it’s not being turned into an int.
Another thing to keep in mind is that these comparisons are in object mesh space, NOT in the actual world space.
F’rinstance, if you have a scale factor of 2, then vertices that appear to be apart by X will only actually be reported as separated by X/2 by your calculations based on the vertex positions.