- Home /
First Person Controller - Problems with footstep audio being played too fast.
Hello world, I am having problems with the First Person Controller asset from the Unity standard assets package. I wanted to change the walking speed of my character so that it is much slower than the default, which I have done, however in doing so I think I may have created a new problem where the footstep audio is being called constantly for each frame. I don't even have to move and the footstep audio is played, and when I do move it appears the audio is repeated over itself each frame, creating a tremendous amount of noise. Can anyone help me fix the scripting so that the footstep audio is normal again? I do not speak C# yet, so when I look at the code, I can't make sense of it. Please help! Below is the default script for the FPC.
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
private void PlayFootStepAudio()
{
if (!m_CharacterController.isGrounded)
{
return;
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
Your answer
Follow this Question
Related Questions
error CS1525: unexpected symbol. How do I fix this and why am I getting this error? 1 Answer
Attacking mulitple targets simultanously 2 Answers
how do i add a offset to my sword rotation? 2 Answers
How can I stop a stopwatch using "on trigger enter"? 2 Answers
What is the best way to detect collision?? Raycast2D, OnTriggerEnter2D, OnCollisionEnter2D 1 Answer