Footstep sounds when walking

Hi

I was wondering how to make footsteps sound when walking only?

Thanks, Chris

Hi Chris,

  1. 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).

  2. 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.

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.

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.

Some basic foot steps script

using UnityEngine;
using System.Collections;

public class FootSteps : MonoBehaviour {

/**

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));

}

}

Or get this asset: Advanced Footstep System | Audio | Unity Asset Store

did that

var som : AudioSource;

function Update()
{

if (Input.GetKeyDown ("w"))
{
    som.Play();
  
}

if (Input.GetKeyUp ("w"))
{
    
    som.Stop();
}

}