Play sound while moving.

I am looking for a script to loop a sound while the player is moving. I can’t have the sound just play while the player is holding down a movement key, because of the sliding mechanic that I have. Is there a way to loop the sound while the acceleration is greater than 0? Also a script to not play the sound while not on the ground would be helpful.

Thank you! :smiley:

2 Answers

2

if(rigidbody.velocity.magnitude >= 0.2)
{
//Play sound here if you have a rigidbody component and if your movement is rigidbody.AddForce
}

Thank You for your help! :D

Hi, try something like this:

if(grounded && acceleration < 0 ){
 if(!audio.isPlaying()){
 audio.clip = yourclip;
 audio.Play();

 }
}

now you have to find a way to determine whether you are touching the ground and set the grounded bool accordingly, for example check whether your collider intersects with a collider of an object with tag “Ground” etc.

Regards BPR

Thank You for your help! :D