Trying to make a float mechanic, kind of like Peach's up-b from smash

Godot Version

v4.1.2.stable.mono.official [399c9dc39]

Question

I am trying to make a mechanic that makes it so you can float down slower by holding down the space button while descending. Whenever I try to implement the code, it just doesn’t work, so I’m looking for help on what to improve to make this work.

My code:

``````extends CharacterBody2D

var screen_size
@export var speed = 500 # How fast the player will move (pixels/sec).

var mana

var jump_velocity = -2000

const acc = 50
const friction = 70
var gravity = 125
var floatgrav = 5

const max_jumps = 2
var current_jumps = 1

func _physics_process(delta):
var input_direction: Vector2 = input()

if input_direction != Vector2.ZERO:
accelerate(input_direction)
\$AnimatedSprite2D.play("walk")
else:
add_friction()
\$AnimatedSprite2D.stop()

player_movement()
jump()

func _ready():
pass

func input() -> Vector2:
var input_dir = Vector2.ZERO

input_dir.x = Input.get_axis("move_left", "move_right")
input_dir = input_dir.normalized()
return input_dir

func accelerate(direction):
velocity = velocity.move_toward(speed * direction, acc)

func add_friction():
velocity = velocity.move_toward(Vector2.ZERO, friction)

func player_movement():
move_and_slide()

func jump():
if Input.is_action_just_pressed("jump"):
if current_jumps < max_jumps:
velocity.y = jump_velocity
current_jumps += 1
else:
velocity.y += gravity

if is_on_floor():
current_jumps = 1

func float():
if Input.is_action_pressed("jump") && velocity.y > 0 && current_jumps >= 0:
velocity.y = velocity.y + (gravity * .2)

func shoot():
pass

``````

I’m not sure you’re ever calling your `float` function. Also, I would avoid using names like `float` as it’s already a keyword. Might cause weird bugs.