(Bootcamp should be free on the asset store)
Yes I was thinking about trigger volumes too... as I have other stuff that needs triggering when entering areas...(snow, rain, music, sound fx) so Ill be setting up my whole game into areas. The only thing for me is roads, they are kind of different. Im thinking that Ill probably only use 3 types of footsteps, earth, road, and floor. floor being all interiors.
I searched my demo projects and found a few scripts, i think the Bootcamp one is this... appearing to work with tags.
public var footAudioSource : AudioSource;
public var woodSteps : AudioClip[];
public var metalSteps : AudioClip[];
public var concreteSteps : AudioClip[];
public var sandSteps : AudioClip[];
private var cc : CharacterController;
private var t : Transform;
public var hitLayer : LayerMask;
private var cTag : String;
function Start()
{
cc = GetComponent(CharacterController);
t = transform;
}
function OnFootStrike ()
{
if(Time.time < 0.5) return;
if(cc != null)
{
volume = Mathf.Clamp01(0.1 + cc.velocity.magnitude * 0.3);
}
else
{
volume = 1;
}
footAudioSource.PlayOneShot(GetAudio(), volume);
}
function GetAudio() : AudioClip
{
var hit : RaycastHit;
//Debug.DrawRay(t.position + new Vector3(0, 0.5, 0), -Vector3.up * 5.0);
if(Physics.Raycast(t.position + new Vector3(0, 0.5, 0), -Vector3.up, hit, Mathf.Infinity, hitLayer))
{
cTag = hit.collider.tag.ToLower();
}
if(cTag == "wood")
{
return woodSteps[Random.Range(0, woodSteps.length)];
}
else if(cTag == "metal")
{
return metalSteps[Random.Range(0, metalSteps.length)];
}
else if(cTag == "concrete")
{
volume = 0.8;
return concreteSteps[Random.Range(0, concreteSteps.length)];
}
else if(cTag == "dirt")
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
else if(cTag == "sand")
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
else
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
}
THEN I found this one from a free monster pack thingy, you add one script to your model and one to the geometry you want to walk on....
I havent tried this, but its might be another way to think... especially if the object that you walk on actual contains the reference to the noise the footsteps would make on it... again, not really working on terrain. But I imagine it could be good in a house, imagine moving from wooden floor, to stone kitchen floor, to carpet...
Anyway, something to study..
FIRST THE SMALL SCRIPT THATS ADDED TO OBJECTS
// Small script to hold a reference to an audioclip to play when the player hits me.
// This script is attached to game object making up your level.
// The "Foot" script (which is attached to the player) looks for this script on whatever it touches.
// If it finds it, then it will play the sound when the foot comes in contact
var audioClip : AudioClip;
var volumeModifier = 1.0;
AND NOW THE ONE THAT YOU ADD TO CHARACTERS...
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)