0 votes

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")
in Engine by (309 points)

what is the Vector2.UP for?

1 Answer

+1 vote
Best answer

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)
by (104 points)
selected by

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).

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.