Z
Z
Zefirot2022-01-16 13:17:23
Unity
Zefirot, 2022-01-16 13:17:23

Why doesn't the vector comparison condition work?

MeshAgent often gives me an array with a vector of 0, 0, 0 , why I don’t understand, but I decided to exclude it from the array altogether

private Vector3 VectorNull = new Vector3(0f, 0f, 0f);
.....
if(MeshCorners.Length > 2){
  int ln = 0;
  foreach(Vector3 vl in MeshCorners){ if(vl != VectorNull){ Debug.Log("XX=> " + vl);  ++ln; }}
  Vector3[] TempMeshCorners = new Vector3[ln]; ln = 0;
  foreach(Vector3 vl in MeshCorners){ if(vl != VectorNull){ TempMeshCorners[ln] = vl; ++ln; }}
  MeshCorners = TempMeshCorners;
  }

yes, that's just the problem, that's what displays me
XX=> (-0.1, -0.2, 0.0)
XX=> (0.0, 0.0, 0.0)
XX=> (1.4, 1.2, 0.0)

i.e. the if(vl != VectorNull) condition does not work, but why? And how to remove a null vector from an array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-01-16
@Zefirot

Because visual 0.0is not mathematical 0. Look in the debugger what the vector actually equals.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question