Footstep sounds not coming up when walking? (MOBILE)

Hello everyone! I seem to be in a a bit of trouble…

I’ve changed up the walking script(s) that apply to PC controls (WASD). I’ve tried to have it to where if the Player’s velocity is anything higher than 0.0, then the walking audio would start. The thing is, there is an audio that plays when I walk, but it’s VERY FAST and it sounds like the sound is having a seizure. Anybody has a clue what I did wrong in this script? :confused:

#pragma strict
@script RequireComponent( AudioSource )
@script RequireComponent( CharacterController )
 
var walkSounds : AudioClip[];
 
var walkAudioSpeed : float = 0.7;
 
private var walkAudioTimer : float = 0.0;
 
var isWalking : boolean = false;
 
var walkSpeed: float = 8; // regular speed
var walkBackwardsSpeed: float = 8;
var walkSidewaysSpeed: float = 8;


private var controller: CharacterController;

function Start()
{
	controller = GetComponent(CharacterController);
}
 
function Update()
{
	var overallSpeed : float = controller.velocity.magnitude;
	
	var velocity: Vector3;
	var horizontalVelocity : Vector3 = controller.velocity;
	horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
	
	if ( controller.isGrounded && overallSpeed > 0.2 )
	{
		audio.Stop();
		audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
		audio.Play();
		walkAudioTimer = 0.0;
	}
	else
	{
		walkAudioTimer = walkAudioSpeed;
		audio.Stop();
	}
}

Try this: Advanced Footstep System

In your Update method, you are stopping and restarting the sound every frame it appears. You should wrap your code that starts the sound playback with a check to see if the sound is not playing first. And if it is not playing, start the new random sound.

#pragma strict
@script RequireComponent( AudioSource )
@script RequireComponent( CharacterController )

    var walkSounds : AudioClip[];
     
    var walkAudioSpeed : float = 0.7;
     
    var walkAudioTimer : float = 0.0;
     
    var controller: CharacterController;
     
    function Start()
    {
    controller = GetComponent(CharacterController);
    }
     
    function Update()
    {
    var overallSpeed : float = controller.velocity.magnitude;
     
    var velocity: Vector3;
    var horizontalVelocity : Vector3 = controller.velocity;
    horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
     
    var controller : CharacterController = GetComponent(CharacterController);
     
    if (controller.isGrounded && controller.velocity.magnitude > 0.2)
    {
    //EDITED CODE
    var flag = false;
    for(var ws :AudioClip in walkSounds)
    {
     if(audio.isPlaying && audio.clip == ws)
     {
         flag = true;
         break;
     }
    }
     if(!flag)
     {
          audio.Stop();
          audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
          audio.Play();
          walkAudioTimer = 0.0;
    }
    if (controller.velocity.magnitude < 0.2)
    {
    walkAudioTimer = walkAudioSpeed;
    audio.Stop();
    }
    }

See if this works… and mark as solved if it does.