- Home /
Random Footsteps with variable pitch and volume
Ive seen some scripts to make random footsteps and also scripts to change the pitch and volume of an audio source, is there a way of combining them together so not only does the audio clip change but the pitch and volume of that audio clip change as well. the scripts are shown below
this is the random audio source script
var audioSources : AudioClip[];
function Start () { audioSources = new AudioClip[5]; }
function OnCollisionEnter(collision : Collision) //or whatever you have now { //when you get to the part where you want to play the sound... var nextClip = audioSources[Random.Range(0, audioSources.Length)]; audio.clip = nextClip; audio.Play(); }
this is the change pitch/volume script
var baseFootAudioVolume = 1.0; var soundEffectPitchRandomness = 0.05;
function OnTriggerEnter (other : Collider) { var collisionParticleEffect : CollisionParticleEffect = other.GetComponent(CollisionParticleEffect);
if (collisionParticleEffect) {
Instantiate(collisionParticleEffect.effect, transform.position, transform.rotation);
}
var collisionSoundEffect : CollisionSoundEffect = other.GetComponent(CollisionSoundEffect);
if (collisionSoundEffect) {
audio.clip = collisionSoundEffect.audioClip;
audio.volume = collisionSoundEffect.volumeModifier * baseFootAudioVolume;
audio.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
audio.Play();
}
}
function Reset() { rigidbody.isKinematic = true; collider.isTrigger = true; }
@script RequireComponent(AudioSource, SphereCollider, Rigidbody)
THANKS GUYS, Matt
Answer by Jesse Anders · Feb 09, 2011 at 06:34 PM
Yes, it can all easily be done.
In essence, you want to take the part of the second script that assign a random pitch and volume, and apply it in the first script right before the sound is to be played.
If you have any trouble doing that, then I'd recommend posting whatever specific questions you have about the process (either as a comment or by editing your post here, or as a new question either here or on the forums), and someone should be able to help.
Your answer
Follow this Question
Related Questions
Random footsteps 5 Answers
Footstep Script Not Working 2 Answers
Footstep sounds when walking 7 Answers
What's the easiest way of changing footsteps sound depending on floor material? 3 Answers
Strange Bug or Code Error with footsteps? -1 Answers