Problem with jumping 2D physics

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Amateur.game.dev.

Basically, whenever i am walking and i spam the jump button my player doesn’t fall back down, he just does more jumps.
Here is the jump physics script

func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if is_on_floor():
	if Input.is_action_pressed("jump"):
		velocity.y = jump_speed
		$PlayerSprite.play("Jump")

what is the Vector2.UP for?

Millard | 2020-08-16 02:11

:bust_in_silhouette: Reply From: mohamedLT

try to use this code

 func _physics_process(delta):
get_input()
velocity.y += gravity * delta
if is_on_floor():
    if Input.is_action_pressed("jump"):
        velocity.y = jump_speed
        $PlayerSprite.play("Jump")
move_and_slide(velocity, Vector2.UP)

Thanks so much for the answer, but this wasn’t the solution. But I did notice that under the code that made the player walk I added script which said:

	if Input.is_action_pressed("walk_right"):
	$PlayerSprite.play("Run2")
	velocity.x += speed
	**if Input.is_action_just_pressed("jump"):
		velocity.y = jump_speed
		$PlayerSprite.play("Jump")**

and

elif Input.is_action_pressed("walk_left"):
	$PlayerSprite.play("Run")
	velocity.x -= speed
	**if Input.is_action_just_pressed("jump"):
		velocity.y = jump_speed
		$PlayerSprite.play("Jump")**

all I needed to do was to delete the extra jump commands and it stopped. (The ** is to show which part I am talking about).

Amateur.game.dev. | 2020-08-16 14:33