Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Dec 02, 2013 at 04:59 AM by AlucardJay for the following reason:

Duplicate Question, asking for script

avatar image
-2
Question by Peanut97 · Nov 23, 2013 at 07:31 PM · audioaudiosourcefootsteps

Help with Simple Footsteps?

Hello,

Can anybody help me create a Simple Footstep script? I have tried writing my own and they work, but they are glitchy. I don't need/want multiple footstep sounds, so really I just a need an audio source to play and stop when I use the "WASD" keys. If anybody could help me out with this, I would really appreciate it! I've been stuck on this for a while, and I would LOVE some help! Thank you for your time!

Comment
Add comment · Show 18
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 TheLivingTree · Nov 23, 2013 at 08:36 PM 0
Share

Did the one I sent you from the other question not help?

avatar image TheLivingTree · Nov 23, 2013 at 08:47 PM 0
Share

$$anonymous$$aybe this tutorial would help you: https://www.youtube.com/watch?v=_cJR6QQ9T94

avatar image Peanut97 · Nov 23, 2013 at 08:58 PM 0
Share

The other one your sent me totally worked! The only problem was whenever I hit "A S or D" when I was already holding W (strafing), The sound would restart. Any ideas on how to make it stay playing even if you hit another key? Thanks for your help, man! I seriously appreciate it!

avatar image TheLivingTree · Nov 23, 2013 at 09:30 PM 0
Share

Ah alright I would check out drak8888's answer on your other question he said some good stuff about using Horizontal and Vertical inputs that might work out better. Wish I could help out more!

avatar image TheLivingTree · Nov 23, 2013 at 10:44 PM 1
Share

Sounds awesome! That's actually exactly what I am working on as well! Yeah please send me a link :D Well without further ado here is the code I put together:

 #pragma strict
 @script RequireComponent(AudioSource)
  
 var AudioFile : AudioClip;
  var controller : CharacterController;
  var player : GameObject;
  var vectorZero : Vector3;
  
  function Start(){
  player = GameObject.Find("Player");
 controller = player.GetComponent(CharacterController);
 vectorZero = Vector3.zero;
 
  }
  
 function Update()
 {
     if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
     {
     if(controller.velocity == vectorZero){
     
         audio.Play();
         
         }
     }
     else if (Input.GetAxis("Horizontal") == 0 || Input.GetAxis("Vertical") == 0)
     {
     
     if(controller.velocity != vectorZero){
         audio.Stop();
         
         }
     }
 }

This should work with $$anonymous$$imal tweaking. I had an audio source attached to my player with this script. Also, I had loop checked.

Show more comments

2 Replies

  • Sort: 
avatar image
0

Answer by Zmiho · Nov 23, 2013 at 09:11 PM

Make Javascript called FootStepsOn:

 var AudioFile : AudioClip;
 function Update() {
 
 if (Input.GetKeyDown (KeyCode.W))
 {
     audio.clip = AudioFile;
     audio.Play();
  
 }
 }


Then make Javascript called FootStepsMute:

 var AudioFile : AudioClip;
 function Update() {
 
 if (Input.GetKeyUp (KeyCode.W))
 {
     audio.clip = AudioFile;
     audio.Stop();
  
 }
 }
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 Peanut97 · Nov 23, 2013 at 09:26 PM 0
Share

This will work and thank you! But will no audio play when I use the other walk keys such as "A" "S" and "D?" For example, if the player walks backwards, won't it be silent? Do you know of any way around this?

avatar image Zmiho · Nov 23, 2013 at 09:40 PM 0
Share

just add something like this:

 if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.A))
 if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.S))
 if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.D))

and for mute the same but .Get$$anonymous$$eyUp

avatar image Peanut97 · Nov 23, 2013 at 09:54 PM 0
Share

But this will make the audio restart if I walk sideways, won't it? Is there anyway to make it not restart?

avatar image
0

Answer by Jellezilla · Nov 23, 2013 at 09:10 PM

Haven't tried it myself but here's my two cent:

If it is for a FPS or similar, where you can't see the feet it should just be something like: if(isWalking) { Footsteps.Play(); }

This however, will not work if it needs to be synchronized with the graphics. Gl :)

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 Peanut97 · Nov 23, 2013 at 09:27 PM 0
Share

Thank you! Yes, it is an FPS so your first approach should work! I'm just trying to make it so the audio plays no matter which direction (or button) the player hits.

Follow this Question

Answers Answers and Comments

20 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Footstep Script Not Working 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Simple footsteps? 1 Answer

Audio source in two different scenes 1 Answer


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