Comparing rb.velocity greater than new vector

A common question in Unity!

When you compare rb.velocity (a Vector3 property) to a new Vector3 using the greater than operator (>), you need to be aware of the following:

  1. Vector3 comparison: In Unity, Vector3 is a struct, not a class. This means that when you compare two Vector3 values using the greater than operator, it will perform a component-wise comparison. In other words, it will compare each component (x, y, z) separately.
  2. NaN (Not a Number): When you create a new Vector3 with no values (e.g., new Vector3()), it will have a NaN value for all components. NaN is a special value that is not equal to any other value, including itself. This means that when you compare rb.velocity to a new Vector3, the comparison will always return false, because rb.velocity is not NaN.
  3. Infinity: When you create a new Vector3 with infinite values (e.g., new Vector3(float.MaxValue)), it will have infinite values for all components. Infinity is a special value that is not equal to any other value, including itself. This means that when you compare rb.velocity to a new Vector3 with infinite values, the comparison will always return false, because rb.velocity is not infinite.

To compare rb.velocity to a new Vector3 in a meaningful way, you need to consider the specific use case and the desired behavior. Here are a few examples:

Remember to consider the units and scales of your game when comparing rb.velocity to a new Vector3.