- Home /
help with footsteps!
I am trying make a footstep sounds when i walk in my First Person Controller. I also would like the footsteps to go faster when i sprint and slower when i crouch. Please help. I'm no coder :(
Comment
Answer by Gikerowski · Feb 23, 2013 at 10:04 PM
Did you try this? : http://answers.unity3d.com/questions/404942/footsteps-sounds.html ?
Answer by Coreyf716 · Feb 23, 2013 at 10:18 PM
public AudioClip walkAudio;
public float audioTimer;
void Update() {
/* This basically asks, "is the timer greater than zero?". If the statement returns true, the timer will begin to decrease in time. You need this to hold a pattern between steps. If you use 'audio.PlayOneShot()' alone, it won't sound right.*/
if (audioTimer > 0)
audioTimer -= Time.deltaTime;
/* This is asking, "is the timer less than or equal to zero (when subtracting by time, Unity will almost never land directly on zero), and is the vertical or horizontal axis greater than zero (these are measured in floats, numbers with a decimal). They must be put in brackets as you'll have issues with an 'and' and 'or' statement together. If all are returned true, the sound will play and the timer will be set to the length of the AudioClip*/
if (audioTimer <= 0 && (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0))
{
audio.PlayOneShot(walkAudio);
audioTimer = walkAudio.length;
}
/* Now, to change the gap between steps, you change the value of the timer. Ex: sprinting - audioTimer = walkAudio.length * 2;*/
}
If you have any questions, feel free to ask.
Your answer
Follow this Question
Related Questions
Random footsteps 5 Answers
Footstep Sound Error toSample > fromSample 1 Answer
Footstep sounds when walking 7 Answers
What's the easiest way of changing footsteps sound depending on floor material? 3 Answers
Strange Bug or Code Error with footsteps? -1 Answers