- Home /
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?
Answer by Bunny83 · Apr 10 at 02:48 AM
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
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613055213im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with a ballistic trajectory simulation (rigidbody.velocity) 0 Answers
Correctly move rigidbody at constant speed 1 Answer
Problems with secondary animation when blending 0 Answers
My animation and player movement are messing with each other 0 Answers
How do I do rigidbody.velocity while ignoring one axis? 0 Answers