I'm trying to create footsteps for my Character Controller. I'm currently doing this by seeing if the controller is grounded, and if they are moving to play to footstep sound. I also check to see if the sound is already playing, so it won't continuously play.
Here's the code:
if (controller.isGrounded && controller.velocity.magnitude > 2f && !footstepSound.isPlaying)
{
footstepSound.volume = Random.Range(.8f, 1f);
footstepSound.pitch = Random.Range(.8f, 1.1f);
footstepSound.Play();
}
But for some reason, the AudioSource sometimes takes longer than it should to play again. The audio clip is .515 seconds long, but it sometimes takes a second or longer to play the audio again. This results in uneven footsteps sounds, even when I comment out the random pitch & volume. What am I doing wrong?
↧