[SOLVED] Trying to make footstep sounds


#1

how do i make footstep sounds? i set it so when the player moves it will play but it only plays when the player stops moving https://playcanv.as/p/OC9jmY7G/


#2

or if i turn on overlap it makes some horrible noises


#3

My guess is that you are trying to play the sound effect every frame that the player is moving so you are hearing nothing until you stop as you keep trying to start the effect each frame.

The way I would do it is to play the effect every X seconds (assuming that the effect is a single footstep) or have a loop that starts playing when you start moving and stop when you stop.


#4

alright then how would i do the loop that starts and stops when moving and not?


#5

like a “if wasd being pressed then play sound but if not stop sound” or something else


#6

alright so i figured it out. this block of code seems to work:


 if (app.keyboard.wasPressed(pc.KEY_A)) {
        this.entity.sound.play("walk");
    }
    if (app.keyboard.wasReleased(pc.KEY_A)) {
        this.entity.sound.stop("walk");
    }
    if (app.keyboard.wasPressed(pc.KEY_D)) {
        this.entity.sound.play("walk");
    }
    if (app.keyboard.wasReleased(pc.KEY_D)) {
        this.entity.sound.stop("walk");
    }
    if (app.keyboard.wasPressed(pc.KEY_W)) {
        this.entity.sound.play("walk");
    }
    if (app.keyboard.wasReleased(pc.KEY_W)) {
        this.entity.sound.stop("walk");
    }
    if (app.keyboard.wasPressed(pc.KEY_S)) {
        this.entity.sound.play("walk");
    }
    if (app.keyboard.wasReleased(pc.KEY_S)) {
        this.entity.sound.stop("walk");
    }