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
    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
in Engine by (12 points)
edited by

I know this is really, REALLY old, but when I put that code in, it says "Unexpected token: "if" by the "isonfloor". What can I do to fix this?

2 Answers

+1 vote

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

by (334 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.

+3 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.

by (66 points)

That fixed it thanks a lot!

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

Yes fixed it for me. Thanks a lot! :)

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.
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 webmaster@godotengine.org with your username.