Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Probably you are executing this code into a loop (_physics_process or _process) and move_and_collide is returning the colision information when it's hits the platform, so $AudioStreamPlayer.play() is always be called. To solve it you can declare a gloal variable thats saves the current touched plataform then check if the current platform is diferent from the saved, so the play function will be called once per platform. Something like this:

var current_platform = null # global variable
[...]
func _physics_process(delta):
     [...]
     var colision = move_and_collide(direction.normalized()) # get collision data
     if colision: # check if is colliding
          if current_platform != colision.collider: # check if the colliding object is different from last one
               current_platform = colision.collider # save current platform
              $AudioStreamPlayer.play() # play the audio

Will be good to set current_platform as null when an action like jump be done for the audio be played when platform be touched again.
There are several other approaches to solve this problem, this is one of them.

  

This bit of code works, but the sound only plays once per scene. Not exactly sure what is causing this, but it is most likely a problem with the node's properties.  Here they are.

P.s: It is a .wav file and none of the import options are on.

(1 edit)

The node options looks good. It might be some logic problem. Take a look in this code: https://github.com/Guizeronet/godot-platform-test/blob/master/obj/char/char.gd

You can download my example and see it running. It is different from my last comment, it can works better. (Download here: https://github.com/Guizeronet/godot-platform-test )

Sorry, but the way you used that logic doesn't fit with what I imagined. Fortunately, the basics of your logic helped me out with sort of what I wanted. So, thanks a bunch!