0 votes

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 JUMPHEIGHT = -400
var motion = Vector2()
func _physics
process(delta):
motion.y += GRAVITY
var friction = false
if Input.isactionpressed("uiright"):
motion.x = SPEED
$Sprite.play("Walk")
$Sprite.flip
h = false
elif Input.isactionpressed("uileft"):
motion.x = -SPEED
$Sprite.play("Walk")
$Sprite.flip
h = true
else:
motion.x = 0
$Sprite.play("Idle")
if isonfloor():
if Input.isactionjustpressed("uiup"):
motion.y = JUMPHEIGHT
motion = move
andslide(motion, UP)
pass
if Input.is
actionjustpressed("dash"):
dash()
if SPEED == 400 and friction == false:
$Sprite.play("Dash")

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

asked Dec 12, 2019 in Projects by Abb1x (18 points)

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

1 Answer

0 votes

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.

answered Dec 12, 2019 by beebanoo (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.