0 votes

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:
        walk.play()
    elif walk.playing:
        walk.stop()

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?

in Engine by (35 points)

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

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. :)

There, Done! :D

1 Answer

+1 vote
Best answer

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:
        walk.play()
elif walk.playing:
    walk.stop()
by (35 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.
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 webmaster@godotengine.org with your username.