Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MegamanXfangamer |
Hello everyone! I have a problem with my landing sound, and that is that I want that when my platform character lands a landing sound is reproduced but it does not work, it is repeated infinitely and I do not know how to solve it, please I ask for your help.
here is the code piece
func _physics_process(delta):
if Velocity.x == 0 or Velocity.y == 0 && is_on_floor() && !is_on_wall():
$Landing.play()
I would suggest a state machine, but that’s a bit more than what’s probably needed for this problem. Maybe you could have a variable which is assigned when the player lands on the floor. After that, check for whether the sound was played. It could look something like this:
func _physics_process(delta):
if Velocity.length() == 0 and is_on_floor() and not is_on_wall() and not sound_has_played:
sound_has_played = true
$Landing.play()
Once the player jumps, assign false
to sound_has_played
.
Ertain | 2022-05-09 23:35