How to make walking sound work

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

I’ve been making a game for a week in Godot now, and I’m pretty happy with it, but I want to add sound effects to it. I did this:

onready var walk = $PlayerWalkSound

if velocity.x != 0 and is_on_floor() and !walk.playing:
	elif walk.playing:

But it doesn’t work. It won’t play the whole sound, it just repeats the first millisecond of it very quickly. The other sounds I use were easier to implement, but this is a little harder for me. Any ideas?

Nvm, don’t bother answering, I solved it.

SoMir | 2020-07-15 15:08

Nvm, don’t bother answering, I solved it.

Care to share the solution here? Might help someone with the same or a similar problem in the future. :slight_smile:

njamster | 2020-07-16 17:50

There, Done! :smiley:

SoMir | 2020-07-16 18:29

:bust_in_silhouette: Reply From: SoMir

Basically what I did is, in the first if statement removed !walk.playing and put it in a nested if under that. Before it would check if it’s playing in the first statement, but if it was it would stop it anyway in elif. Now, elif doesn’t get called if it’s playing everytime.

if velocity.x != 0 and is_on_floor():
    if !walk.playing:
elif walk.playing:
1 Like

I got this to work by omitting the elif from my function.

if velocity.length() != 0:
	# if the footstep audio isn't playing, play the audio
	if !footstep_audio.playing:
		footstep_audio.pitch_scale = randf_range(.8, 1.2)