0 votes

I'm creating a state machine for my player with the current states atm:
- Idle;
- Running;
- Jump;
- Falling;

All the states works fine, but now I want to implement a double jump, so my question is:
do I need to apply the "jump force" again before or after the moveandslide?
Like that:

velocity = move_and_slide(velocity, Vector2.UP)
If Input.is_action_just_pressed("jump") and jumps < 1:
   jumps += 1
   init_jump()

Here's the init_jump:

func init_jump():
    anim = ""
    state = states.JUMP
    velocity.y = jump_speed  # -300
in Engine by (171 points)

1 Answer

0 votes

it doesn't matter it could just be in with the get input function packed in one test for jump button event it doesn't need to be in two places. I expect it would not work reliably and if the button was not pressed quickly enough it would just jump twice as high. if I was making a double jump the second jump would test velocity.y and not allow the second jump until velocity.y hit a certain point, your jump speed reads as - 300 so when you jump velocity.y goes to - 300 then starts climbing back to zero so I would test if jumps == 0 then test if jumps == 1 and velocity.y > -100 , then tweak it from there. would also need to be a Boolean to say the player jumped to test when player isonfloor after a jump to reset the jumps variable the way yours is if you jump once the variable becomes 1 then if you jump it becomes 2 and you cant double jump, your snip shows no reset of the jumps variable

on jump button event jumping = true
if jumping and isonfloor(): jumping = false, jumps = 0

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