How to make jump button not slow down character falling

Godot Version

4.7

While falling, if i spam the up key i slow my fall, any tips on how to fix this?

The code is:

extends CharacterBody2D

@onreadyonready var coyote_timer: Timer = $CoyoteTimer
@onready var jump_buf_timer: Timer = $JumpBufTimer

var coyote_time_activated: bool = false

const jump_height: float = -486.0
var gravity: float = 15.0
const max_gravity: float = 20.5

var max_speed: float = 200
var acceleration: float = 11
const friction: float = 12

func _physics_process(delta: float) → void:
var x_input: float = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
var velocity_weight: float = delta * (acceleration if x_input else friction)
velocity.x = lerp(velocity.x, x_input * max_speed, velocity_weight)

if is_on_floor():
	coyote_time_activated = false
	gravity = lerp(gravity, 15.0, 15.0 * delta)
else:
	if coyote_timer.is_stopped() and !coyote_time_activated:
		coyote_timer.start()
		coyote_time_activated = true
	if Input.is_action_just_released("ui_up") or is_on_ceiling():
		velocity.y *= 0.45
	
	gravity = lerp(gravity, max_gravity, 15.0 * delta)
	
if Input.is_action_just_pressed("ui_up"):
	if jump_buf_timer.is_stopped():
		jump_buf_timer.start()

if !jump_buf_timer.is_stopped() and (!coyote_timer.is_stopped() or is_on_floor()):
	velocity.y = jump_height
	jump_buf_timer.stop()
	coyote_timer.stop()
	coyote_time_activated = true

if velocity.y < jump_height/4.0:
	var head_col: Array = [$L_HeadNudge.is_colliding(),$L_HeadNudge2.is_colliding(),$R_HeadNudge.is_colliding(),$R_HeadNudge2.is_colliding()]
	if head_col.count(true) == 1:
		if head_col[0]:
			global_position.x += 2
		if head_col[2]:
			global_position.x -= 2

if velocity.y > -250 and velocity.y < 100 and abs(velocity.x) < 5:
	if $L_LedgeHop.is_colliding() and !$L_LedgeHop2.is_colliding() and velocity.x < 0:
		velocity.y += jump_height*0.5
	if $R_LedgeHop.is_colliding() and !$R_LedgeHop2.is_colliding() and velocity.x > 0:
		velocity.y += jump_height*0.5

velocity.y += gravity
move_and_slide()

Seems like this line is reducing your fall/jump speed

the issue isn’t that the fall speed is slow, the issue is that while mid air by spamming the up key i can cut up my fall in to shorter falls, thus making me have more air time. how would i go about fixing this?

Prevent jumping when falling. And yeah, the line @gertkeno mentioned is where you need to intervene.

I would assume you want to remove the lines I posted, or at at least the input check. The code is very directly stating “If you press this button, cut velocity.y in ~half” Could you explain why it is there, what you hope it would do?

What you do here is, you decrease your velocity when ‘you press up’ or when ‘you are on ceiling’. This means you fall slower. Or in other words, it takes longer to fall to the floor.

If you don’t want press up button effect falling, add ‘and is_on_floor()’ to if statement. So it should be:

If Input.is_action_just_released("ui_up") and is_on_floor()

Considering the quoted code is part of a not-on-floor condition, then your sample will never run. Here’s the full quote.

Right. I didn’t check the full code. Then that part should move to if part of the statement