[SOLVED] Footsteps only play when in motion

I want footstep sounds to play when moving but stop when not plz help

What is your question?

I want footstep sounds to play when the player moves, I was tryin to put it into this script
https://playcanvas.com/editor/code/1009294?tabs=111800426

That’s possible. I would do it in the CheckMotion function I guess. Make sure you start the sound once at a time.

ok but where?

Did you try to read and understand the code of that function?

yes, I am trying multiple things

Right now I am trying

HeadBobController.prototype.CheckMotion = function () {
    var velocity = this.entity.rigidbody.linearVelocity.clone();
    velocity.y = 0;
    var speed = velocity.length();

    if (speed < 1) return;
    if (speed < 1) this.entity.sound.play('Slot 1');
    
    
    //if (!this._controller.isGrounded) return;
    
    this.PlayMotion(this.FootStepMotion());
    
};

I dont understand

I think you should use line 2 to stop the sound. Then copy the line and change < with > to play the sound.

The only problem then is that you start the sound repeatedly, so you also need to check if the sound is not playing already.

ok but right now the sound wont play at all unless I replace the return with the playsound :frowning:

Ah yes that’s correct, the return line should be after your sound lines.

So I swap places?

Yes, that’s correct.

ok let me try that one sec

OMG it works! Thank you so much :smiley:

1 Like

It is constantly playing footsteps I think :expressionless:

It doesn’t stop when you stop moving?

idk it kinda wierd