The walking sound doesn't works for the player once he lands after jumping

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

Errr… You’re going to have to post some relevant code or a link to your project before anyone can offer you any useful assistance…

jgodfrey | 2020-08-17 19:08

What is the code???

Amateur.game.dev. | 2020-08-17 19:27

For future reference, this is not an Answer, but rather a comment. Use the Comment mechanism when additional info is required (though, I already did that above).

jgodfrey | 2020-08-17 19:30

okay I’ll change it to a comment

Amateur.game.dev. | 2020-08-17 19:39

Ok so basically I have a vector2 variable velocity…now the code goes like

if velocity.x!=0:
$WalkingSound.play()

else //when horizontal velocity is zero:
$WalkingSound.stop()

Now basically what I want is when I move the player the walking sound should play and when he stops the sound should stop…I first tried using Input.is_action_just_pressed…but the problem is when the player jumps the Audio frame resets when the player lands as a result the walking sound doesn’t play…so I synced the audio with the horizontal velocity… now the audio is working as I want it to but a wierd blurry sound is coming

i_am_dhrutiman1999 | 2020-08-19 17:38

:bust_in_silhouette: Reply From: jgodfrey

Calling $WalkingSound.play() will start playing your sound from the beginning each time it’s called. I can only guess that’s what’s leading to the described “blurry sound”. You probably only want to play the sound if it’s not already playing. This small change should help:

if velocity.x != 0 && !$WalkingSound.playing:
    $WalkingSound.play()

So, only play the sound if 1) you’re moving and 2) the sound isn’t already playing…

Thanks man it worked!!!

The only change i had to make to your suggested code was

if velocity.x !=0 :
if $Walking_Sound.playing:
$Walking_Sound.play()

And it worked wonders … thanks a lot !!!

i_am_dhrutiman1999 | 2020-08-19 18:39

Hmmm… Glad you have it working, but the code you posted is not what I intended. Specifically, that code you posted above will only play the sound if it’s already playing - which doesn’t really make sense. The difference being that you’re missing a not modifier (!) at the beginning of the $WalkingSound.playing check.

Maybe you just neglected to type it in the above-posted code?

And, if you really do have the ! in your actual code, then it’s logically the same as the code I posted above, so I’m not sure why you had to change it.

But, as I said, glad you have it working…

jgodfrey | 2020-08-19 19:01

Oh yes…that’s a typo my bad…but when I used your original code my Player’s Running animation wasn’t working due to some reason so I made this slight change…but doesn’t matter… your concept helped solve the problem…thanks a lot bro

i_am_dhrutiman1999 | 2020-08-19 19:14