Won't the Y velocity of a Rigidbody2D be 0 at some point?

Hi guys. I am making a test platformer game in unity2D. I am having no problem with my player movement code. I just wanted to clarify a doubt. First have a look at my code :

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody2D player;
    private float hAxis; 
    public float moveSpeed = 5f;
    public float jumpSpeed = 5f;

    private void Start()
    {
        player = GetComponent<Rigidbody2D>(); 
    }

    private void Update()
    {
        hAxis = Input.GetAxisRaw("Horizontal");
        if (Input.GetButton("Jump") && (player.velocity.y == 0))
        {
            player.velocity = new Vector2(moveSpeed * hAxis, jumpSpeed);
        } else
        {
            player.velocity = new Vector2(moveSpeed * hAxis, player.velocity.y);
        }
    }
}

The code’s working fine. But i have a doubt at this line :

if (Input.GetButton("Jump") && (player.velocity.y == 0))

I wrote this line so that my player can jump continuously if the user holds the jump button continuously as well as it doesn’t fly. But still, when we reach the highest point of our jump, won’t the Y velocity be 0 again? From what I know, yes, the Y velocity should be 0 again. But, If it does, the code shouldn’t work. Still it is working. Please explain to me why doesn’t the Y velocity happen to be 0. I am pretty new to unity. Please help.

Well, in the real world this is true. At some point in time the y-velocity would be 0. However the real world does not “simulate” in discrete time steps but it’s a continuous process. Just for example I assume we still have the usual gravity of “9.81 m/s²”. That means you will subtract 9.81 from your y - velocity every second. Since we usually have a framerate of about 60 frames, we only subract 1/60 of that amount which would be about “0.1635” every frame. So if you go up at a velocity of say 2.5 it would take 15 frames to get down to 0.0475. Now the next frame we again subtract 0.1635 so we get a new velocity of -0.116. As you can see we passed “0” without ever having the value 0.0 ever encountered. Keep in mind that is almost impossible to exactly reach a certain value with floating point numbers through mathematical operations. Even if the value is 0.00000001 it’s still not 0 even you wouldn’t notice any movement at that velocity.