0 votes

I want to make a double jump for my player, i have this code from a tutorial but it doesn't work.It only jumps once. Also, what values are better for jumping?

var jumps_left=2
var jump_power = -185
var gravity = 15
var velocity = Vector2()

func _physics_process(delta):
   velocity = move_and_slide(velocity, Vector2.UP)

func jump():
   if is_on_floor():

   if Input.is_action_pressed("ui_up") and jumps_left>0:
       if velocity.y>0:
           velocity.y=0 #if falling- ignore fall velocity
       velocity.y += jump_power 
       jumps_left -= 1

   velocity.y += gravity
in Engine by (92 points)

1 Answer

+2 votes
Best answer

Try using Input.is_action_just_pressed to jump only when you just pressed the button, because with Input.is_action_pressed you jump every frame when the action is pressed (and you can only jump twice). For values it entirely depends on your project, you should experiment. https://docs.godotengine.org/en/stable/classes/class_input.html#class-input-method-is-action-just-pressed

by (291 points)
selected by

Thank you that solved it!

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.