extends CharacterBody2D @export var speed = 340; @export var gravity = 50; @export var jump_count = 2; @export var jump_strength = 100 var jump_count_current = 2; var input_direction = 0 #To keep track of which direction we where moving in last frame func get_input(): var left = Input.is_action_pressed("player_left") var right = Input.is_action_pressed("player_right") if left and right: input_direction = input_direction elif left: input_direction = -1 elif right: input_direction = 1 else : input_direction = 0 velocity.x = input_direction * speed if is_on_floor(): jump_count_current = jump_count if Input.is_action_just_pressed("player_jump") and jump_count_current > 0: velocity.y = -1 * jump_strength jump_count_current = jump_count_current-1 elif Input.is_action_pressed("player_jump"): #Fall less fast if we keep holding the button velocity.y += -1 * 25 func _physics_process(delta): get_input() velocity.y += gravity move_and_slide()