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 Cherikov · Aug 18, 2012 at 11:35 AM · movementaudiosoundsprint

Sprinting Audio Problem

Hey, I would like to ask how to add a sprinting sound to my game. I already have a system that allows me to play footsteps but I want to know how to make these sounds play at a faster rate while running?

This is my footstep Script:

 var walkSounds : AudioClip[]; // fill this array with the sounds at the Inspector
 
 var audioStepLength = 0.3;
 
 
 
 function Start(){
 
     var controller : CharacterController = GetComponent(CharacterController);
 
     while (true) {
 
         if (controller.isGrounded && controller.velocity.magnitude > 0.4) {
 
             audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
 
             audio.Play();
 
             yield WaitForSeconds(audioStepLength);
 
         } else {
 
             yield;
 
         }
 
     }
 
 }

EDIT

Ok, I have been suggested the following script - how do I combine them? Im spatially 'slow' when it comes to scripting

SUGGESTED SCRIPT

 var walk:AudioClip;
 var run:AudioClip;
 
 if(walk){
   audio.clip=walk;
   audio.Play();
 }else if(run){
   audio.clip=run;
   audio.Play();
 }
Comment
Add comment · Show 4
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 MC HALO · Aug 19, 2012 at 09:57 AM 0
Share

do you want to add sprint sound to the player ?

avatar image Cherikov · Aug 19, 2012 at 09:33 PM 0
Share

yes, but It must have both footsteps and running footsteps... How Do?

avatar image fafase · Aug 20, 2012 at 06:18 AM 0
Share

run is running steps, walk is footsteps. audio.clip = clip; is switching the clip before using them. Your script shows two variable slots (run/walk) in the Inspector. Simply drag the audio files in there.

avatar image Cherikov · Aug 20, 2012 at 08:17 AM 0
Share

it doesnt work :( how about editing the script so that it will play walking sounds when velocity is above 0.4 but below 10 and when the velocity is above 10 play running footsteps:

so ins$$anonymous$$d of being just 0.4 its > 0.4 < 10???

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Aug 18, 2012 at 11:39 AM

Modifying the pitch of the audio source result in a faster tempo but also a higher pitch.

In your case, I would recommend using Audacity (free), you can easily (really easily) fast up the speed of a file and lower its pitch to make it sound ok. It tkes about a couple of trials and 5min.

Then import your new sound as usual and:

 var walk:AudioClip;
 var run:AudioClip;
 
 if(Input.GetKey(KeyCode.R) && Input.GetKey(KeyCode.Akey)){
   Run();
   audio.clip=run;
   audio.Play();
 }elseif(Input.GetKey(KeyCode.Akey)){
   Walk();
   audio.clip=walk;
   audio.Play();{
 }else
   audio.Pause();

You could use this simple principle. Make sure the playing is looped. The runing is based on how your guy moved plus pressing r (r is checked first to save cycle). If r is not pressed, then maybe the movement is on but you are walking. Then is nothing then you are not walking the stepping stops. The complicated part compared to way 2 is that you need to manually tweak the animation speed to make the sound and steps match. Immersion would not like if you hear a step while the foot is up.

EDIT:Way2

You can use animation event easily.

The curve of your right and left foot should look like a sin wave (going up and down). Create a single step sound (just "pac";, no "pac-pac-pac").Add an event when the green curve of the feet animations are at the lowest and add this:

 var step:AudioClip;
 
 function StepSound(){
 AudioSource.PlayClipAtPoint(step,transform.position);
 }

Attach this to the right and left feet. Then follow the tutorial in the link http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html

Do the same process for the running. The curves have a higher frequency, your running sound happens more often. You are running.

Comment
Add comment · Show 6 · 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 Cherikov · Aug 19, 2012 at 07:30 AM 0
Share

Ok sweet! how would I implement this though?

avatar image Cherikov · Aug 19, 2012 at 07:37 AM 0
Share

how do I add this:

var walk:AudioClip; var run:AudioClip;

if(walk){ audio.clip=walk; audio.Play(); }else if(run){ audio.clip=run; audio.Play(); }

Do I have to add this to my script or what? how do i do this! I'm a noob when it comes to javascripting

avatar image fafase · Aug 19, 2012 at 10:12 AM 0
Share

Yes you add this to the movement script. I updated the answer.

avatar image Cherikov · Aug 19, 2012 at 09:35 PM 0
Share

Sweet! thanks! ill try it now

avatar image Cherikov · Aug 19, 2012 at 09:38 PM 0
Share

hold on? which script do i add it to?: $$anonymous$$y Sprinting and crouching or the Footstep Script?

Show more comments

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

10 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

Related Questions

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

How to play Audio Once if enemy has enterd a trigger 1 Answer

Procedural native audio synthesis with OnAudioFilterRead 1 Answer

How To Turn Off Sound For Certain Objects? 1 Answer

How to play sound when object stops moving? 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