# Rigidbody's velocity values are constantly going all over the place even when idle. How do I fix?

Hey guys as the title says, my velocity values are going pretty haywire and I’d just like to hear some input on what could be going wrong. Here’s a minute long video I took of this:

I have no idea what’s going wrong with the x value but the y value I’ve noticed acts the way it should when the player doesn’t stand on top of a composite collider (which is pretty freakin’ weird considering if you want proper physics, you’d want your player to walk on a composite collider)

It hasn’t really become a problem for me yet with the x value because all my animations are working just fine spite of it going all over the place however with my y value it has been. Because I’m trying to execute a code that checks if my velocity.y is <= 0, and if so it’ll turn off one of my colliders. Else if it’s greater than 0, it’ll have my collider on. Thing is, my collider is always on because once I take that first step, my velocity.y will always be greater than 0 even though it really shouldn’t be.

That is normal: those are very small numbers. If you expand the width of the inspector, you’ll see that velocities are like 8.323456e-6, which is the scientific representation of 0.000008323456, that is, a very small residual speed. When dealing with rigidbodies they’re typically not stopped, but moving at negligible speed.

Because of this, you shouldn’t compare with exact zero. That only happens at specific cases, and even in those cases they might evaluate == 0 to be false. Use a threshold to detect whether the rb is moving, like this:

``````bool isMoving = rb.velocity.magnitude > 0.00001f;
``````
1 Like

The velocity will also stop changing by these tiny values when it sleeps but the fact that it’s not sleeping would indicate that you’re continually waking it up. You do this indirectly by doing things like adding zero forces, changing the Transform or setting the same position/rotation via MovePosition/MoveRotation etc.

If nothing is happening (no input from the user) then you should not be performing any write operations on the Rigidbody2D.

You can see its current sleep state in the “Rigidbody2D > Info” foldout.

2 Likes

Thank you guys

2 Likes