Topic was automatically imported from the old Question2Answer platform.
Asked By
Serenade
Old Version
Published before Godot 3 was released.
Hey!
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?
Use a bool to turn landed property from false to true and ignore further collisions.
Like:
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
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
#get_node("Get_Back_to_FloorSND").play()
#getbacktofloor_sound.play()
# 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)
else:
if motion.y < 0:
#$Sprite.play("Jump")
null
else:
#$Sprite.play("test")
null
if friction == true:
motion.x = lerp(motion.x, 0, 0.05)
motion = move_and_slide(motion, up)
pass
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.