rigidbody.velocity.y problem

Hello!

I am having a problem with my vertical velocity.

Basically, I want to see if my character’s up and down velocity is changing to know if it is jumping. The problem is that, even though my character is not moving in the y axis (up and down), the y velocity is still has a value which ranges at around 9. I know this because I am using [SerializeField] on a Vector3 that every update is equalized to rigidbody.velocity.y. I can also see that the character’s y position is the same always. I am not modifying the velocity variable anywhere in my code.

Have I understood velocity wrong? Should I retake physics class? What could my problem be?

Any help appreciated.

I can’t say I know why your game is reporting a velocity when there is none. However, velocity is not a great way to tell if your character is jumping in any case. One reason is that at the very height of your jump, your character’s velocity will be zero (or close to it). The typical way people do this is keep an “isGrounded” boolean variable around, and update it in OnCollisionEnter() and OnCollisionExit() when the other collider is the ground.

1 Like

Thanks for the tip! The problem is that my player is hovering above the ground always. I think I will change some stuff with the movement. I realize that it won’t work in the long run.

Ah, that is tricky! Nevertheless a grounded check or a “nearly grounded” check can be done either by way of trigger colliders that are larger than your character’s model or downward-facing raycasts to measure distance to the ground.