Search Unity

Foot Step Sound Effects Script Help...

Discussion in 'Scripting' started by BHS, Jan 9, 2010.

  1. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Pretty self explanatory, I need help creating a script that will create sound effects every time I walk, I have the sounds all I need is some help.

    Thanks
     
  2. Raziaar

    Raziaar

    Joined:
    Dec 20, 2009
    Posts:
    82
    Is it a third person game where you can see every time your character physically takes a step, or is it just a first person viewpoint where the player would have no real indication of when the feet are hitting?

    This might prove useful to the person who develops your script.
     
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Oh yeah that's kind of important lol. Well I'm developing an RPG game like Oblivion, (Yes I know really complex and I don't even know how to script) but I can model really well, anyways it could be a first person, that's a lot easier to script and to model. If anyone could help me out that'd be awesome, I am making a free to the public game so, help would be appreciated.
    Thanks,
     
  4. Raziaar

    Raziaar

    Joined:
    Dec 20, 2009
    Posts:
    82
    You could of course have the script be developed that the audio is generated whenever the character physically takes a step(something I do not know how to do) and simply apply that to a FPS game as well(if an actual character model is created for reflections and stuff).

    Would be more robust that way.
     
  5. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Alright cool and if anyone could just whip up a script to add to the fps script so It'd make walking sound effects thad be awesome.
     
  6. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
  7. sinu

    sinu

    Joined:
    Jan 28, 2009
    Posts:
    65
    check out the 2d platformer demo, it has triggers on the feet and plays a sound every time the triggers enter the ground.
     
  8. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    if its FPS, im now working on a script to do just that. Its not complete, as it needs 4 sounds per tag and to be random and needs way more surfaces depending on the game, but this should be an example:
    Code (csharp):
    1. //This is the walking sound script. It uses 4 sound files per tag. Objects can only be tagged once, so only use this on terrain if no need for other tag.
    2.  
    3. var concreteSound1 : AudioClip;
    4. var sandSound1 : AudioClip;
    5. private var isWalking : boolean = true;
    6. var footstepTime : float = 0.2;
    7. private var isMoving : boolean = false;
    8. private var isJumping : boolean = false;
    9. private var isOnConcrete : boolean = false;
    10.  
    11. function Update() {
    12.     if (Input.GetAxis("Horizontal")) {
    13.         isMoving = true;
    14.         } else if (Input.GetAxis("Vertical")) {
    15.         isMoving = true;
    16.         } else if (Input.GetButtonDown("Jump")) {
    17.             isMoving = true;
    18.             isJumping = true;
    19.         } else if (!Input.GetButton("Jump")) {
    20.             isMoving = false;
    21.             isJumping = false;
    22.         }
    23.         //In order for jump to work, there must be a delay in the time from jump button press to actual jump in order for it to register. Also, ensure GetButtonDown on the player jump script, otherwise, it wont work right.
    24.         else if (!Input.GetAxis("Horizontal")) {
    25.         isMoving = false;
    26.      } else if (!Input.GetAxis("Vertical")) {
    27.         isMoving = false;
    28.      }
    29. }
    30.  
    31. function OnControllerColliderHit (hit : ControllerColliderHit) {
    32.     if (hit.gameObject.tag == "Concrete"  isWalking  isMoving || isJumping  isWalking  isOnConcrete) {
    33.         Debug.Log ("Walking On Concrete");
    34.         isOnConcrete = true;
    35.         WalkOnConcrete();
    36.     } else if (hit.gameObject.tag == "Sand"  isWalking  isMoving || isJumping  isWalking) {
    37.         Debug.Log ("Walking On Sand");
    38.         isOnConcrete = false;
    39.         WalkOnSand();
    40.     }
    41. }
    42.  
    43. function WalkOnConcrete() {
    44.     var concreteToPlay : GameObject = GameObject.FindWithTag ("Concrete");
    45.     isWalking = false;
    46.     yield WaitForSeconds (footstepTime);
    47.     audio.PlayOneShot (concreteSound1);
    48.     isWalking = true;
    49. }  
    50.  
    51. function WalkOnSand() {
    52.         var sandToPlay : GameObject = GameObject.FindWithTag ("Sand");
    53.     isWalking = false;
    54.     yield WaitForSeconds (footstepTime);
    55.     audio.PlayOneShot (sandSound1);
    56.     isWalking = true;
    57. }
    Hope this helps somewhat :D
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Oh yeah, thanks this helps, so if I were to get four different sound files and added them in then it would work?