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 /
avatar image
0
Question by Halo500 · Jan 29, 2014 at 06:52 AM · audiomobilewalkingcharacter controlling

Footstep sounds not coming up when walking? (MOBILE)

Hello everyone! I seem to be in a a bit of trouble...

I've changed up the walking script(s) that apply to PC controls (WASD). I've tried to have it to where if the Player's velocity is anything higher than 0.0, then the walking audio would start. The thing is, there is an audio that plays when I walk, but it's VERY FAST and it sounds like the sound is having a seizure. Anybody has a clue what I did wrong in this script? :/

 #pragma strict
 @script RequireComponent( AudioSource )
 @script RequireComponent( CharacterController )
  
 var walkSounds : AudioClip[];
  
 var walkAudioSpeed : float = 0.7;
  
 private var walkAudioTimer : float = 0.0;
  
 var isWalking : boolean = false;
  
 var walkSpeed: float = 8; // regular speed
 var walkBackwardsSpeed: float = 8;
 var walkSidewaysSpeed: float = 8;
 
 
 private var controller: CharacterController;
 
 function Start()
 {
     controller = GetComponent(CharacterController);
 }
  
 function Update()
 {
     var overallSpeed : float = controller.velocity.magnitude;
     
     var velocity: Vector3;
     var horizontalVelocity : Vector3 = controller.velocity;
     horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
     
     if ( controller.isGrounded && overallSpeed > 0.2 )
     {
         audio.Stop();
         audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
         audio.Play();
         walkAudioTimer = 0.0;
     }
     else
     {
         walkAudioTimer = walkAudioSpeed;
         audio.Stop();
     }
 }
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 supernat · Jan 29, 2014 at 07:04 AM 0
Share

What parts work, and what doesn't work? What kind of debugging have you done so far?

avatar image DaveA · Jan 30, 2014 at 07:03 AM 0
Share

$$anonymous$$eep an eye out for 'Advanced Footstep System' co$$anonymous$$g soon to an Asset Store near you. http://bit.ly/1dENxco

avatar image Halo500 · Jan 31, 2014 at 06:53 AM 0
Share
 #pragma strict
 @script RequireComponent( AudioSource )
 @script RequireComponent( CharacterController )
  
 var walkSounds : AudioClip[];
  
 var walkAudioSpeed : float = 0.7;
  
 var walkAudioTimer : float = 0.0;
 
 var controller: CharacterController;
 
 function Start()
 {
     controller = GetComponent(CharacterController);
 }
  
 function Update()
 {
     var overallSpeed : float = controller.velocity.magnitude;
     
     var velocity: Vector3;
     var horizontalVelocity : Vector3 = controller.velocity;
     horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
     
     var controller : CharacterController = GetComponent(CharacterController);
     
     if (controller.isGrounded && controller.velocity.magnitude > 0.2)
     {
             audio.Stop();
                audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
                audio.Play();
                walkAudioTimer = 0.0;
     }
     if (controller.velocity.magnitude < 0.2)
     {
         walkAudioTimer = walkAudioSpeed;
            audio.Stop();
     }
 }


I've changed up the code here a little bit, but it's the same concept and I'm still getting some sort of weird static sound...

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Feb 11, 2014 at 07:04 AM

Try this: Advanced Footstep System

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 supernat · Feb 11, 2014 at 07:11 AM 0
Share

FYI, my virus scanner shows this as a suspicious site. Are you sure about the link?

avatar image
0

Answer by supernat · Jan 31, 2014 at 07:08 AM

In your Update method, you are stopping and restarting the sound every frame it appears. You should wrap your code that starts the sound playback with a check to see if the sound is not playing first. And if it is not playing, start the new random sound.

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
0

Answer by sumeetkhobare · Feb 11, 2014 at 07:43 AM

     #pragma strict
     @script RequireComponent( AudioSource )
     @script RequireComponent( CharacterController )
      
     var walkSounds : AudioClip[];
      
     var walkAudioSpeed : float = 0.7;
      
     var walkAudioTimer : float = 0.0;
      
     var controller: CharacterController;
      
     function Start()
     {
     controller = GetComponent(CharacterController);
     }
      
     function Update()
     {
     var overallSpeed : float = controller.velocity.magnitude;
      
     var velocity: Vector3;
     var horizontalVelocity : Vector3 = controller.velocity;
     horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
      
     var controller : CharacterController = GetComponent(CharacterController);
      
     if (controller.isGrounded && controller.velocity.magnitude > 0.2)
     {
     //EDITED CODE
     var flag = false;
     for(var ws :AudioClip in walkSounds)
     {
      if(audio.isPlaying && audio.clip == ws)
      {
          flag = true;
          break;
      }
     }
      if(!flag)
      {
           audio.Stop();
           audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
           audio.Play();
           walkAudioTimer = 0.0;
     }
     if (controller.velocity.magnitude < 0.2)
     {
     walkAudioTimer = walkAudioSpeed;
     audio.Stop();
     }
     }


See if this works.. and mark as solved if it does.

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

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

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

Footstep Audio Not Working? 1 Answer

Footsteps Script for Running and Walking 3 Answers

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

How do I fix audio loop delay 2 Answers

Footstep Script Not Working 2 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