• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by cmos · Feb 14, 2010 at 10:25 AM · animationaudioanimationeventfootsteps

Footstep sounds when walking

Hi

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

Thanks, Chris

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image UCRussian · Nov 06, 2012 at 02:44 AM 1
Share
  1. Create javascript in your project (empty) and move it onto your FIRST PERSON CONTROLLER

  2. Open the script (right click EDIT)

  3. Delete what ever is in there.

  4. 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();

 }

}


  1. Safe the File.

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

avatar image DaveA · Feb 09, 2014 at 03:47 AM 0
Share

Or get this asset: http://u3d.as/content/qlc/advanced-footstep-system/6o2

avatar image GMAGames · Dec 30, 2015 at 03:37 PM 0
Share

great script dot

6 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2
Wiki

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cmos · Feb 14, 2010 at 09:04 PM 0
Share

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.

avatar image
9

Answer by Nicolaj Schweitz · Feb 15, 2010 at 09:06 AM

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.
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

}

}

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vaupell · Jan 17, 2014 at 10:53 PM 0
Share

This script is great - Jan 2014

avatar image Halo500 · Feb 06, 2014 at 03:33 AM 0
Share

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!

avatar image GMAGames · Dec 30, 2015 at 02:34 PM 0
Share

great script dot

avatar image
0

Answer by waimiandtheday · Aug 03, 2013 at 01:02 AM

did that

var som : AudioSource;

function Update() {

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

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

footstep audio sync probs 0 Answers

Footstep Script Not Working 2 Answers

problems with pressing a button to run the animation. 0 Answers

Trying to play other objects' sound and animations from Raycast hit 1 Answer

Play Audio in Animation Window 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges