- Home /
Footstep sounds when walking
Hi
I was wondering how to make footsteps sound when walking only?
Thanks, Chris
Create javascript in your project (empty) and move it onto your FIRST PERSON CONTROLLER
Open the script (right click EDIT)
Delete what ever is in there.
Copy and paste this code in your E$$anonymous$$PTY SCRIPT FILE:
5. Just name it FootStepsOn (or what ever you like)
var AudioFile : AudioClip;
function Update() {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.W))
{
audio.clip = AudioFile;
audio.Play();
}
}
Safe the File.
Left click on your FIRST PERSON.
7. Add a footstep sound in your script.
NOTE: If you gonna add a long audio file in to that script it's gonna play till its end, so to fix that shit go on and create a new JAVASCRIPT and name in FootSteps$$anonymous$$ute and add this script into it (just like you did the first one)
var AudioFile : AudioClip;
function Update() {
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.W))
{
audio.clip = AudioFile;
audio.Stop();
}
}
Good Luck dog.
Or get this asset: http://u3d.as/content/qlc/advanced-footstep-system/6o2
Answer by jashan · Feb 14, 2010 at 10:37 AM
In most cases, you'll probably just start a looped sound whenever you start your walking animation, and stop the sounds when you stop the walking animation. Obviously, you need footstep sounds from somewhere: Either you simply get a sound library that has looped footsteps, or you create the sounds yourself.
You could also try to sync the sounds with your animation which would be more realistic but also significantly more challenging to implement. In other words: When the left foot "touches" the floor, you trigger one sound, when the right foot "touches" the floor, you trigger another sound.
In general, it's usually a good idea to have a couple of different sounds to chose from to avoid the walking sounds getting too repetetive and boring. You might also consider having different sounds for different rooms / types of floor to improve the "feeling" for the rooms / types of floor. Like: Footsteps inside a hall sound quite different from footsteps on the grass in a forest.
Answer by Nicolaj Schweitz · Feb 15, 2010 at 09:06 AM
Hi Chris,
I think the best place to start looking at audio that is bound to animation is AnimationEvents. Basically, you need to attach a script that plays the sound at the animation's frame where the sound needs to played (or perhaps a little later if your sound has a long attack).
When playing sounds that don't need to be in sync with animations the AnimationEvent method is a bit overkill. In that case I'd simply loop the sound while moving.
Both methods will need a little scripting skills, but nothing to be afraid of :)
Blowing features into it: I'd ad some conditions to when the sound can be played and some nice-to-have features:
- e.g. if character is grounded,
- different audio clips depending of movement direction
- random pitch
- random audio clips (for non trivial experience)
- trigger zones for different ground surfaces
- trigger zones for different environments
- etc.
Answer by Ricardo · Feb 14, 2010 at 08:02 PM
Jashan mentions the possibility if syncing the sound with the animation, which is correct, and not really as challenging. Even if you're a newbie you can find how to do it on the 2D Gameplay Tutorial. It also shows how to kick up dust with the steps for good measure.
Another alternative to that collider approach would be using animation events that tie in with the specific moment of the footfall, and change the sound depending on the surface your character is walking on. I'm not aware of any tutorial that shows how to do that, but it's probably something you want to look into.
Thanks for your response. I don't really need it to sync with any animation, since it will be in first person view. Just when the first person view moves to make the footsteps sound.
Answer by koushik.s · Jul 29, 2013 at 09:12 AM
Some basic foot steps script
using UnityEngine; using System.Collections;
public class FootSteps : MonoBehaviour {
/**
Script made by OMA [www.oma.netau.net] **/
public CharacterController controller; public AudioClip[] concrete ; public AudioClip[] wood ; public AudioClip[] dirt ; public AudioClip[] metal ; public AudioClip[] glass ; public AudioClip[] sand; public AudioClip[] snow; public AudioClip[] floor; public AudioClip[] grass;
private bool step = true; float audioStepLengthWalk = 0.45f; float audioStepLengthRun = 0.25f;
void OnControllerColliderHit ( ControllerColliderHit hit) {
if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Untagged" && step == true ) {
WalkOnConcrete();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Concrete" && step == true || controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Untagged" && step == true) {
RunOnConcrete();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Wood" && step == true) {
WalkOnWood();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Wood" && step == true) {
RunOnWood();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Dirt" && step == true) {
WalkOnDirt();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Dirt" && step == true) {
RunOnDirt();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Metal" && step == true) {
WalkOnMetal();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Metal" && step == true) {
RunOnMetal();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Glass" && step == true) {
WalkOnGlass();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Glass" && step == true) {
RunOnGlass();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Sand" && step == true) {
WalkOnSand();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Sand" && step == true) {
RunOnSand();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Snow" && step == true) {
WalkOnSnow();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Snow" && step == true) {
RunOnSnow();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Floor" && step == true) {
WalkOnFloor();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Floor" && step == true) {
RunOnFloor();
} else if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Grass" && step == true) {
WalkOnGrass();
} else if (controller.isGrounded && controller.velocity.magnitude > 8 && hit.gameObject.tag == "Grass" && step == true) {
RunOnGrass();
}
}
IEnumerator WaitForFootSteps(float stepsLength) { step = false; yield return new WaitForSeconds(stepsLength); step = true; } /////////////////////////////////// CONCRETE //////////////////////////////////////// void WalkOnConcrete() {
audio.clip = concrete[Random.Range(0, concrete.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnConcrete() {
audio.clip = concrete[Random.Range(0, concrete.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
////////////////////////////////// WOOD ///////////////////////////////////////////// void WalkOnWood() {
audio.clip = wood[Random.Range(0, wood.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnWood() {
audio.clip = wood[Random.Range(0, wood.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
/////////////////////////////////// DIRT ////////////////////////////////////////////// void WalkOnDirt() {
audio.clip = dirt[Random.Range(0, dirt.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnDirt() {
audio.clip = dirt[Random.Range(0, dirt.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// METAL /////////////////////////////////////////////// void WalkOnMetal() {
audio.clip = metal[Random.Range(0, metal.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnMetal() {
audio.clip = metal[Random.Range(0, metal.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// GLASS /////////////////////////////////////////////// void WalkOnGlass() {
audio.clip = glass[Random.Range(0, glass.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnGlass() {
audio.clip = glass[Random.Range(0, glass.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// SAND /////////////////////////////////////////////// void WalkOnSand() {
audio.clip = sand[Random.Range(0, sand.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnSand() {
audio.clip = sand[Random.Range(0, sand.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// SNOW /////////////////////////////////////////////// void WalkOnSnow() {
audio.clip = snow[Random.Range(0, snow.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnSnow() {
audio.clip = snow[Random.Range(0, snow.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// FLOOR /////////////////////////////////////////////// void WalkOnFloor() {
audio.clip = floor[Random.Range(0, floor.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnFloor() {
audio.clip = floor[Random.Range(0, floor.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
////////////////////////////////// GRASS /////////////////////////////////////////////// void WalkOnGrass() {
audio.clip = grass[Random.Range(0, grass.Length)];
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
}
void RunOnGrass() {
audio.clip = grass[Random.Range(0, grass.Length)];
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForFootSteps(audioStepLengthRun));
}
}
EDIT: Alright! This one works perfectly! Thanks a lot! I've downloaded the script from the YouTube video's link and it was in Javascript and this must have been the original edit, which could mean that the Javascript conversion could have went wrong for the creator at some point...
Thanks koushik.s and Vaupell!
Answer by DaveA · Feb 06, 2014 at 03:30 AM
Or get this asset: http://u3d.as/content/qlc/advanced-footstep-system/6o2