- Home /
Play different sounds on different surfaces?
How to play different footstep audio sounds when within triggers or on different surfaces?
Ok so been searching around quite a bit and found some close answers but I cannot get them to work. So starting from the ground up here. I have a script that allows footstep audio sounds to played when walking. Now I need to find a way to add to this code so when my capsule collider is walking on/in different triggers or on different surfaces it plays different sounds. EXAMPLE: Character walking on wood plays footstep sounds that sound like walking on wood and if character walks onto a carpet it plays carpet footstep sounds.
This is as far as I am so far.
var audioStepLength = 0.3;
var walkSounds:AudioClip[];
var footAudioRandomness = 0.1;
var soundEffectPitchRandomness = 0.05;
function Start ()
{ var controller : CharacterController = GetComponent(CharacterController);
while (true)
{
if (controller.isGrounded && controller.velocity.magnitude > 0.3)
{
audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
audio.volume = Random.Range(0.4 - footAudioRandomness, 0.4 + footAudioRandomness);
audio.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
audio.Play();
yield WaitForSeconds(audioStepLength);
}
else
{
yield;
}
}
}
Any solid ideas? Any and all help is greatly appreciated.
Answer by Kryptos · Oct 19, 2012 at 08:44 AM
I will go this way:
Use different tag for different ground surface.
In your coroutine, cast a ray vertically to check the tag of the surface.
Depending on the tag, play a different sound and/or adjust the pitch or other values of some filters.
Your answer
Follow this Question
Related Questions
Varied footsteps - Object reference not set to an instance of an object? 2 Answers
Continuous RayCast on GetButtonDown 0 Answers
Raycast to trigger audio from other script on hit? 2 Answers
Footsteps Script for Running and Walking 3 Answers
Footsteps sound on collision problem, please help!!! 0 Answers