0 votes

So I have a variable call "jump_count" so what I tried is:

if is_on_floor():
    jump_count = 3
elif not is_on_floor():
    jump_count -= 1

This just takes 1 jump each frame , and doesn't just take one jump if I'm not on the ground.

Godot version 3.2.3.stable.official
in Engine by (12 points)

1 Answer

0 votes

It seems as though you are checking whether or not you are on the ground each frame, and if you are not then decrease by 1 each step.

What would be better is when you jump to reduce the jump_count variable within your jump function, and then if you have enough "jumps left" then you can jump.

# called when on floor and jump button pressed
func jump():
    # reduces count by 1
    jump_count -= 1
    # if you have enough counts left then jump
        if jump_count != 0:
           motion.y = -JUMP_FORCE
by (144 points)
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.