i need help with AudioStreamPlayer3D

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

i have 12 second walk sound audio, when press walk the aduio doesn’t play instead it loops from 0 so it is just buffering and wont play the full audio. here is my code:

"extends KinematicBody

onready var walk = $AudioStreamPlayer3D

func ready():

if Input.is_action_pressed(“ui_up”):

can someone help? it only works if i use “action_just_pressed”
but that is not accurate.

:bust_in_silhouette: Reply From: Yaann

That’s because you’re calling the function every single frame with isactionpressed, I would suggest you instead to put the audio inside an AnimationPlayer, put it in a loop and call the animation instead.

I tried it but it can’t stop playing, the animation stops but the audiostream continues to play.

umma | 2021-05-25 16:49

I figured it out now i had to write a script that stop the audio stream also, have a look:

if Input.is_action_pressed(“ui_left”) and (is_on_floor() or ground_check.is_colliding()):
elif Input.is_action_just_released(“ui_left”):

umma | 2021-05-25 18:32

yeah it’s good, that’s how it is supposed to work!

Yaann | 2021-05-25 18:41