I'm designing an oldschool Spectrum-like platformer where I need several jump tweaks I can't quite figure out.

Two problems with the player code below:
1. The player jumps only with
if Input.is_action_pressed("player_jump"):
Problem with the jump sound is that it retriggers every frame, whereas I need it only to play once. Which happens if I set it to
if Input.is_action_just_pressed("player_jump"):
- but then the player will jump only very low. How can I fix this? Should I use justpressed?
2. I need to set the maximum jump height after which the velocity.y will lerp to gravity pull. There will be tiles in the game that let the player jump higher (temporarily. How should I do that better?
Here's the code:
extends KinematicBody2D
var airborne
var movingright
var velocity = Vector2()
var walkspeed = 400
var gravityscale = 600
var jumpvelocity = 1300
func _ready():
movingright = true
func teleport_to(target_pos):
position = target_pos
func get_input():
if Input.is_action_pressed("ui_right"):
movingright = true
airborne = false
$SnoozyAnim.play("walk")
velocity.x = walkspeed
elif Input.is_action_pressed("ui_left"):
movingright = false
airborne = false
$SnoozyAnim.play("walk")
velocity.x = - walkspeed
else:
$SnoozyAnim.play("idle")
airborne = false
velocity.x = lerp(velocity.x, 0, 0.2)
if not movingright:
$SnoozyAnim.set_flip_h(false)
else:
$SnoozyAnim.set_flip_h(true)
if Input.is_action_pressed("player_jump"):
velocity.y -= jumpvelocity
airborne = true
$SnoozyAnim.play("jump")
$JumpSound.play()
func _physics_process(delta):
velocity.y = gravityscale
get_input()
move_and_slide(velocity)