How to play a sound when the player jump

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

I want that my player made an sound when he jump there is my code :

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
var SPEED = 200
const JUMP_HEIGHT = -400
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
var friction = false
if Input.is_action_pressed(“ui_right”):
motion.x = SPEED
$Sprite.play(“Walk”)
$Sprite.flip_h = false
elif Input.is_action_pressed(“ui_left”):
motion.x = -SPEED
$Sprite.play(“Walk”)
$Sprite.flip_h = true
else:
motion.x = 0
$Sprite.play(“Idle”)
if is_on_floor():
if Input.is_action_just_pressed(“ui_up”):
motion.y = JUMP_HEIGHT
motion = move_and_slide(motion, UP)
pass
if Input.is_action_just_pressed(“dash”):
dash()
if SPEED == 400 and friction == false:
$Sprite.play(“Dash”)

func dash():
SPEED = 400
$Timer.start()
func _on_Timer_timeout():
SPEED = 200

First of all, go watch a tutorial man, there are plenty(probably),
second of all, when the play simply jump you play the audio.

rustyStriker | 2019-12-12 07:01

:bust_in_silhouette: Reply From: beebanoo

First, you need to add AudioStreamPlayer to your player node and set the stream property to the audio file you want to play.
Second, during the handling of the jump input action, you need to reference that AudioStreamPlayer and call the play() method.