0 votes

I want my player object to make a sound when it lands, but if i detect collision or such, sound is played constantly (like, "trrrrrrrrrrrr....")
How can i make it sound only once per collision with ground?

in Engine by (227 points)
recategorized by

1 Answer

–1 vote
Best answer

You need to control the program flux (if).

Use a bool to turn landed property from false to true and ignore further collisions.


if collision implies landing (not landed and other things you control)
-> play sound
-> mark the player as landed so it won't enter the if anymore

by (7,922 points)
selected by

Hello, i know that is the old post and i have the same problem. I was searching for this type of tutorial of this language, but can't find any proper one. I develop mostly in C# and VB in .NET environment so this GD language is quite a strange one to me, altough i have read the documentation i can't fully understand it.

But how would the code look like?

I figured it out all the way to moving the player, and almost all code that is about playing the sound only once i commented out as non-working.

if is_on_floor():
        playerIsLanded = true


#       if playerIsLanded == true:
#           getbacktofloor_sound.play()
#       else:
#           getbacktofloor_sound.stop()    

        if Input.is_action_just_pressed("Jump"):
            motion.y = jump_height
        if friction == true:
            motion.x = lerp(motion.x, 0, 0.2)
            if motion.y < 0:

        if friction == true:
            motion.x = lerp(motion.x, 0, 0.05)

    motion = move_and_slide(motion, up)

I am using both Waveform and Vorbis sound containers, and in import settings all of my sounds in this test project have LOOP turned off in Import tab, so this is not the problem.

Is there a method that can be called like this:


instead of this:


Thanks for feedback

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.