- Home /
Rigidbody Velocity.Y is a random number!
I check rigidbody.velocity.y to find if the character is either jumping up, dropping down or stationary. But at certain points in the level, for no apparent reason, the value is a weird number. But what's weirder than that number is the velocity vector is (0, 0, 0), and velocity. y is something else.
Debug.Log("Velocity Up is: " + myRigidbody.velocity.y + " and velocity is: " + myRigidbody.velocity);
The above code logs this, Velocity Up is: 6.208779E-09 and velocity is: (0.0, 0.0, 0.0)
"6.208779E-09" = 0.000000006208779, which is pretty much 0. This is called E-notation
Vector's will round when printed, which is why you don't see that number when printing the velocity vector.
Thanks for the link. But the prob is that, it still returns true for (velocity.y > 0) and that's a problem for me. Don't think I can use, $$anonymous$$athf.Round, coz 0.01 will also become 0, am I right? How can I get the best value of it?
Answer by sidtri2 · Oct 03, 2017 at 07:36 AM
Based on the reply posted by bobisgod234, I made a slight change to my code. So instead of checking if velocity.y > 0, I am checking if velocity.y > 0.0001f. This even though it works, still kinda feels like a hack. If there is a better way, I'd love to know it. Thanks.
I would consider using $$anonymous$$athf.Approximately
Your answer
Follow this Question
Related Questions
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Countering AddForce by Modifying velocity 3 Answers
Sum of multiple velocities 1 Answer
Rigidbody velocity disables gravity 1 Answer
Rigidbody Character 1 Answer