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

in Engine by (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.

by (18 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.