0 votes

Player just jumps once. Can someone tell me whats wrong?

var velocity = Vector2()
var on_ground = false
var has_double_jumped = false

if is_on_floor():
    on_ground = true
else:
    on_ground = false

if Input.is_action_pressed("ui_up"):
    if on_ground == true:
        velocity.y = JUMP_POWER 
        has_double_jumped = false
        on_ground = false

    elif on_ground == false and has_double_jumped == false:
        velocity.y = JUMP_POWER
        has_double_jumped = true
asked May 15, 2019 in Engine by pp09 (12 points)
edited May 15, 2019 by volzhs

2 Answers

+1 vote

Shouldn't you set double_jumped to false when it's on ground ?

answered May 15, 2019 by usurun (322 points)

Just tryed but still it does nothing.
Managed only to make it jump infinite times or just one.
DonĀ“t understand what's not working in my script.

But thanks!

Same here. I've tried do this on diffrent tutorials and no one solve my problem :< Player still jump only one time or infinite if I toggle of "is on floor" script.

+2 votes

Just in case you haven't figured it out yet, change the Input.is_action_pressed("ui_up")to Input.is_action_just_pressed("ui_up")

The reason it didn't work is because Input.is_action_pressed("ui_up")checks if the button is being held down, thus when you press it, the first and second jump gets executed at the ame time, making it look like a single jump.

answered May 15, 2019 by Fenderbate (64 points)

That fixed it thanks a lot!

Oh, thanks! Now it's works! ^w^

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 How to use this Q&A? before posting your first questions.