- Home /
How to add footsteps to Lerpz?
Hi,
I've been trying to build my own 3D platform demo using the Lerpz 3D platform tutorial as a basis. I've made a sample platform and my own character. Managed to also put sounds for jumping, landing but I can't figure out how to put the sounds for the footsteps.
I tried adding an audiosource to the player and used audio.Play() whenever the character moves and is grounded but it played the audio rapidly. Same thing goes when set the condition to function with the animation state(walk).
I tried using the footsteps script from the 2D tutorial and even though there were no errors, it still didn't work :(
What's the best(and optmised) way of creating footsteps?
Thanks very much.
-Hakimo
Answer by Nishanth.du · Nov 28, 2010 at 06:45 AM
Hello,I am Nishanth Hegde.Even I had the same problem before but now it is historied!I have a very simple way of adding sounds. Enter this scrip into your FPScontroller.
var audioStepLength = 0.3; var walkSounds:AudioClip[];
function Start () { var controller : CharacterController = GetComponent(CharacterController);
while (true)
{
if (controller.isGrounded && controller.velocity.magnitude > 0.3)
{
audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
audio.Play();
yield WaitForSeconds(audioStepLength);
}
else
{
yield;
}
}
}
add this to your FPS.Then add a audio listener to the Main Camera.Change the size to 1 in the script and add footstep sound to it.Then click Play and then u shd have ur sound :)
Thanks very much Nishanth :) $$anonymous$$anage to sort it out.
Hey! i really like this script! It worked for me as well. But i also have an issue. I also have background music too. And well it seems to stop playing the background music when i walk. how can i fix this?>
Add an empty game object to your scene , then add audio source to it and put your background music on that because only one sound sample will play at a time on one object. I'm still new to Unity so if anyone knows different please correct me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075743im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Footstep Script Not Working 2 Answers
Random footsteps 5 Answers
Footstep sounds when walking 7 Answers
What's the easiest way of changing footsteps sound depending on floor material? 3 Answers