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
1
Question by Fuzzfas · Jun 07, 2012 at 11:51 PM · audiomaterialsfootsteps

AngryBots MaterialImpactManager Script and FootstepsAudio

I played through the AngryBots scene that comes with Unity and noticed that the footstep sounds do not change in accordance with the type of material the player/character is walking on. I am pretty new to scripting and Unity in general, but it seems like the FootstepHandler script and MaterialImpactManager script are supposed to be responsible for making this happen, but for some reason it's not working when playing the game.

How would one modify these scripts to make this happen? It looks like the scripts are set up for this, but maybe something is missing? Any help would be appreciated.

Here is the FootstepHandler code:


         #pragma strict
     
     enum FootType {
         Player,
         Mech,
         Spider
     }
     
     var audioSource : AudioSource;
     var footType : FootType;
     
     private var physicMaterial : PhysicMaterial;
     
     function OnCollisionEnter (collisionInfo : Collision) {
         physicMaterial = collisionInfo.collider.sharedMaterial;
     }
     
     function OnFootstep () {
         if (!audioSource.enabled)
         {
             return;
         }
         
         var sound : AudioClip;
         switch (footType) {
         case FootType.Player:
             sound = MaterialImpactManager.GetPlayerFootstepSound (physicMaterial);
             break;
         case FootType.Mech:
             sound = MaterialImpactManager.GetMechFootstepSound (physicMaterial);
             break;
         case FootType.Spider:
             sound = MaterialImpactManager.GetSpiderFootstepSound (physicMaterial);
             break;
         }    
         audioSource.pitch = Random.Range (0.98, 1.02);
         audioSource.PlayOneShot (sound, Random.Range (0.8, 1.2));
     }
 
 
 ----------
 
 And here is the MaterialImpactManager code:
 
 
 ----------
 #pragma strict
 
 class MaterialImpact {
     var physicMaterial : PhysicMaterial;
     var playerFootstepSounds : AudioClip[];
     var mechFootstepSounds : AudioClip[];
     var spiderFootstepSounds : AudioClip[];
     var bulletHitSounds : AudioClip[];
 }
 
 class MaterialImpactManager extends MonoBehaviour {
     var materials : MaterialImpact[];
     
     private static var dict : System.Collections.Generic.Dictionary.<PhysicMaterial, MaterialImpact>;
     private static var defaultMat : MaterialImpact;
     
     function Awake () {
         defaultMat = materials[0];
         
         dict = new System.Collections.Generic.Dictionary.<PhysicMaterial, MaterialImpact> ();
         for (var i : int = 0; i < materials.Length; i++) {
             dict.Add (materials[i].physicMaterial, materials[i]);
         }
     }
     
     static function GetPlayerFootstepSound (mat : PhysicMaterial) : AudioClip {
         var imp : MaterialImpact = GetMaterialImpact (mat);
         return GetRandomSoundFromArray(imp.playerFootstepSounds);
     }
     
     static function GetMechFootstepSound (mat : PhysicMaterial) : AudioClip {
         var imp : MaterialImpact = GetMaterialImpact (mat);
         return GetRandomSoundFromArray(imp.mechFootstepSounds);
     }
     
     static function GetSpiderFootstepSound (mat : PhysicMaterial) : AudioClip {
         var imp : MaterialImpact = GetMaterialImpact (mat);
         return GetRandomSoundFromArray(imp.spiderFootstepSounds);
     }
     
     static function GetBulletHitSound (mat : PhysicMaterial) : AudioClip {
         var imp : MaterialImpact = GetMaterialImpact (mat);
         return GetRandomSoundFromArray(imp.bulletHitSounds);
     }
     
     static function GetMaterialImpact (mat : PhysicMaterial) : MaterialImpact {
         if (mat && dict.ContainsKey (mat))
             return dict[mat];
         return defaultMat;
     }
     
     static function GetRandomSoundFromArray (audioClipArray : AudioClip[]) : AudioClip {
         if (audioClipArray.Length > 0)
             return audioClipArray[Random.Range (0, audioClipArray.Length)];
         return null;
     }
 }



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 Fuzzfas · Jun 08, 2012 at 03:44 AM 0
Share

If you have the AngryBots project and the AngryBots.unity scene file to open, I can tell you exactly what I see, and maybe you can deter$$anonymous$$e if everything is set up the way it's supposed to:

Upon opening the scene, if you go to the Hierarchy->$$anonymous$$isc->Caches, and look in the inspector pane, there appear to be an array of audio files link to specific Physic materials called $$anonymous$$etal, Catwalk, and Enemy.

Then, if you go back to the Hierarchy->Environment(static)->Catwalks->catwalk_A->polySurface486, it has a $$anonymous$$esh Collider component, and under $$anonymous$$aterial, it's selected as Catwalk.

When I try to walk along the catwalk with my character, I'm not hearing the array of player_ fs_catwalk audio files that I'm expecting to hear listed in the $$anonymous$$aterial Impact $$anonymous$$anager script. I feel like something must be wrong with the code?

avatar image Bunny83 · Jun 08, 2012 at 03:50 AM 0
Share

I don't see any reason why the code shouldn't work. $$anonymous$$aybe you messed something up in your project. Try to put some temporary Debug.Logs in the code to see what got executed. You can also get the audio clip name right before you play it. There are hundreds of ways to debug your project, however that's up to you...

avatar image Bunny83 · Jun 08, 2012 at 03:54 AM 0
Share

btw, you posted an answer, but it's not really an answer. I've converted it into a comment. Also you posted it 3 times. Your post got stuck in the moderation queue because you don't have enough karma to directly post ( > 15). So just be patient. Every user with 1000+ karma can publish your posts.

avatar image rooted · Oct 03, 2013 at 09:48 PM 0
Share

I'm also experiencing the same thing with this demo. The footsteps are not matching the material. I checked that all the files and file names are correct and correctly referenced in the scripts to my best ability but I can't figure out why they are not working correctly. I am not a coder but would like to know how to resolve this issue. Will an experienced coder see if they can debug this issue and explain how they did so for future reference? The OP did a good job finding the correct scripts for reference.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 07, 2012 at 11:55 PM

Well i never played around with the AngryBots sample, but i guess it should work ;) Are you sure your colliders have a PhysicMaterial set? I don't talk about visual materials on the renderer. It's about the PhysicMaterial of the collider components which define the physical properties of the object.

Also you need to setup the material->sound array with your footstep sounds.

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

6 People are following this question.

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

Related Questions

How do I determine which frame an animation is currently playing? 1 Answer

Different Surface Footstep Sounds Whilst using W and E keys for footstep input 2 Answers

Footstep Audio Not Working? 1 Answer

FPS Footstep Audio Plays Too Quickly 1 Answer

Footsteps Script for Running and Walking 3 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