double jump and values

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sakura37

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
:bust_in_silhouette: Reply From: 1234ab

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. Input — Godot Engine (stable) documentation in English

Thank you that solved it!

Sakura37 | 2020-03-26 21:17