In my game, the player can jump if the up button is pressed and they are on the ground. The velocity.y is also supposed to be set to 0 when on the ground, but when printing the velocity, velocity.y keeps jumping between 0 and whatever value velocity.y was before the player lands.
e.g.

The problem with this is that sometimes I'll press up while on the ground and the player won't jump, probably because at the moment i pressed up it was on the random value rather than 0.
my code:

thanks in advance