Why does rigidbody.velocity.x return crazy float values?

So I’m trying to pass the velocity of a rigidbody to a Mecanim parameter.

Vector3 speed = rb.velocity / maxSpeed;

anim.SetFloat("SpeedY", speed.z);
anim.SetFloat("SpeedX", speed.x);

I convert the speed value between -1 and 1 and when I read just the Vector3 of speed, it’s correct. Remains 0,0,0 when the rigidbody is stationary and gradually increases to max speed of 1 or -1 depending on direction, even works correctly with an analog joy stick.

But when I try to pass speed.x or speed.z to Mecanim, I get wildly fluctuating numbers like -8.1242410e-10 up to 9.43251-e9 even when stationary.

The crazy thing is, it still technically works. The bars in the 2D blend tree still correspond correctly with the level of input, the numbers are just crazy and because they’re constantly fluctuating it makes the blend parameters in the blend tree jittery.

Why is there such a crazy discrepancy between the Vector3 of rb.velocity and the individual vertices of rb.velocity? And how do I get them to display correctly in Mecanim and not be so jittery?

Those are not crazy numbers, that’s just extremely small numbers. You may want to learn about the scientific notation. as well as floating point numbers in general.

So your number -8.1242410e-10 is actually -0.0000000008124241 so essentially 0.