x


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

more ▼

asked Feb 09 '11 at 05:33 PM

Kinglouis33 gravatar image

Kinglouis33
8 4 5 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Feb 09 '11 at 06:34 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1029
x824
x55

asked: Feb 09 '11 at 05:33 PM

Seen: 1442 times

Last Updated: Feb 09 '11 at 05:33 PM