Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Aug 14, 2015 at 05:16 AM by getyour411 for the following reason:

Duplicate Question

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Harardin · Aug 13, 2015 at 01:48 PM · audioscriptingbasicsfpscontrollersound on key

Collider With a FootStep sound.

Hi to every one I need to create a footsteps sound when character moving, and make it different on different surface. Can I use the Collider.OnTriggerStay(Collider) be used to create a footsteps sound with a hit.transform.collider.tag == “tag”? Before of this I tried to use ControllerColliderHit.collider but it didn’t helped Also I use non standard FPS controller. My FPS controller

public class rigBodyControl : MonoBehaviour { public float speed = 10.0f; public float gravity = 10.0f; public float maxVelocityChange = 10.0f;

 private bool grounded = false;



 void Awake()
 {
     rigidbody.freezeRotation = true;
     rigidbody.useGravity = false;
     
 }
 
 void FixedUpdate()
 {
     GetComponent<MainControlAnimation>();
     if (grounded)
     {
         // Calculate how fast we should be moving
         Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         targetVelocity = transform.TransformDirection(targetVelocity);
         targetVelocity *= speed;
         
         // Apply a force that attempts to reach our target velocity
         Vector3 velocity = rigidbody.velocity;
         Vector3 velocityChange = (targetVelocity - velocity);
         velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
         velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
         velocityChange.y = 0;
         rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
         
        
      
        
     }

     // We apply gravity manually for more tuning control
     rigidbody.AddForce(new Vector3(0, -gravity * rigidbody.mass, 0));

     grounded = false;
 }

 void OnCollisionStay()
 {
     grounded = true;
 }

}

Comment
Add comment · Show 6
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 Harardin · Aug 13, 2015 at 02:41 PM 0
Share

I dissuaded to switch on a standard FPS controller.

avatar image Harardin · Aug 13, 2015 at 03:10 PM 0
Share

Trying to use ControllerColliderHit.collider but in this code but its "Lenght" part in audio.clip = concreteSound[Random.Range(0, concreteSound.Lenght)];has no does not contain a definition.

     public CharacterController controller;
     public AudioClip concreteSound;
     private bool step = true;
     float audioStepLengthWalk = 0.45f;
     // Use this for initialization
     void Start () {
         controller = GetComponent<CharacterController>();
     }
     void OnControllerColliderHit (ControllerColliderHit hit)
     {
         //Debug.Log("Controller hit the ground");
         if (controller.isGrounded && controller.velocity.magnitude < 7 && controller.velocity.magnitude > 5 && hit.gameObject.tag == "Untagged" && step == true )
         {
             WalkOnConcrete();
         }
     }
     IEnumerator WaitForFootSteps(float stepsLength)
     {
         step = false;
         yield return new WaitForSeconds(stepsLength);
         step = true;
     }
     public void WalkOnConcrete ()
     {
         audio.clip = concreteSound[Random.Range(0, concreteSound.Lenght)];
         audio.volume = 0.1f;
         audio.Play();
         StartCoroutine(WaitForFootSteps(audioStepLengthWalk));
     }
     
 }
 


Anybody have advise what I miss?

avatar image getyour411 · Aug 14, 2015 at 04:20 AM 0
Share

There are so many tuts/vids/duplicate questions on this topic already. Also, its length not Lenght

avatar image GiyomuGames · Aug 14, 2015 at 04:49 AM 0
Share

Is it not better to do a ray cast on the ground and check its type?

avatar image getyour411 GiyomuGames · Aug 14, 2015 at 05:18 AM 0
Share

closing as duplicate.

avatar image savlon · Aug 14, 2015 at 04:51 AM 0
Share

Why not create a method in your script that deter$$anonymous$$es which collider/surface it's touching and then plays its corresponding sound. Then call that method during your run/walk animation timelines with an event.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to mute my volume 2 Answers

How to prevent an audio clip being spammed? 1 Answer

Audio plays only once and not playing on click of button again(using audio manager script) 0 Answers

Audio is repeating. 3 Answers

How to string multiple audio clips together 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