Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by jyandel · May 02, 2016 at 06:40 PM · footsteps

Footsteps, landing sounds when jumping (javascript)

I'm using a simple first person controller for teaching a class in game audio. I'm using Unity 4 since the school hasn't updated to 5 yet. The script I've been using has worked fine: it gives me a variable that allows me to adjust the footstep speed:

 var footStepSounds : AudioClip[]; //array
 var stepLength = 0.3;
 function Awake () //this is so we load up the sounds right away
 
 {
     PlayFootstepSounds();
 }
 
 //at bottom:
 
 function PlayFootstepSounds()
 {
     var controller : CharacterController = GetComponent(CharacterController);
 
 while (true)
 {
     if (controller.isGrounded && controller.velocity.magnitude > 0.3)
     {
         audio.clip = footStepSounds[Random.Range(0, footStepSounds.length)];
         audio.Play();
         yield WaitForSeconds (stepLength);
     }
     else
         {
             yield;
         }
     }
 }


However, when jumping, I would like to have a landing sound before the footsteps resume. I looked around the forums here and found a script that I modified:

  var footStepSounds : AudioClip[];
  var landSound : AudioClip;
  var moveSpeed : float = 0.3;
  
  private var hasJustLanded = true; 
     
  function Awake()
  {
      //PlayFootStepSounds();
  }
  function Start () {
      
   
  }
  function Update(){
  PlayFootStepSounds();
  
  }
  function PlayFootStepSounds()
  {
       var controller : CharacterController = GetComponent(CharacterController); 
      var isMoving = Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d");
      if (controller.isGrounded) {
          if (isMoving) {
              Debug.Log("I'm walking");
              if (!audio.isPlaying) {
                   audio.clip = footStepSounds[Random.Range(0, footStepSounds.length)];
                  audio.Play();
                  yield WaitForSeconds (moveSpeed);
              }
          }
          else if (audio.isPlaying)
          { 
              audio.Stop();
          }
          
          if (!hasJustLanded) {
              hasJustLanded = true;
              Debug.Log("yo I just landed, where you at?");
              AudioSource.PlayClipAtPoint(landSound, transform.position);
              Debug.Log("BOOM");
          }
      }
      else {
          if (audio.isPlaying)
          { 
              audio.Stop();
          }
          Debug.Log("yo check dis out am flyin! :D");
          hasJustLanded = false;
      }
  }
 

The problem is that I can't adjust the moveSpeed, or rather my adjustments don't work. I'm fairly new to scripting, so apologies if this is really simple, but if anyone can help out I would greatly appreciate it!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Random Footsteps with variable pitch and volume 1 Answer

How can I create headbobbing with footstep sounds and running? 1 Answer

Moving a character's legs and feet using one key to initiate lifting of a foot, then an analog stick / directional keys to move the foot to a target. 2 Answers

Changing Footstep Sounds On Different Surfaces 0 Answers

Footstep Sound Error toSample > fromSample 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