- Home /
Footstep Audio Check Collider Hitting Floor
I have a small script that says to loop the footstep audio if the character is moving. This works great, however it references the inputs, meaning if the character is in the air the sounds still play.
This script is attached to a collider trigger, and what I want is the audio to play when the collider hits a tagged object and the axis input is active, that way not only will it solve the issue but allow me to expand and add extra surfaces, grass, snow etc.
The script so far is:
var Walk : AudioClip;
function Update () {
if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal"))
{
if(!audio.isPlaying)
audio.Play();
audio.loop = true;
}else
audio.loop = false;
}
Any ideas how I could achieve this?
Answer by kkirkfield · Mar 24, 2014 at 02:19 AM
I would suggest parenting a GameObject to the feet bones and using a Collider component on it. Then maybe use GetComponentsInChildren to get the feet colliders. Then just add a check to see if the colliders are touching the ground. Or even better, add a callback function on the player that runs the input check, have it called by a script on the collider object I mentioned above when its OnTriggerEnter function is called.
Your answer
Follow this Question
Related Questions
Why isnt OnTriggerEnter Tags working. 1 Answer
Footsteps script not working 2 Answers
Footstep Script Not Working 2 Answers
Random Audioclip. No Repeat ?? 1 Answer
Sound on collision 3 Answers