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):
   jump()
   velocity = move_and_slide(velocity, Vector2.UP)

func jump():
   if is_on_floor():
       jumps_left=2

   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
asked Mar 26 in Engine by Sakura37 (82 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

answered Mar 26 by 1234ab (128 points)
selected Mar 26 by Sakura37

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