- Home /
My Footstep isn't working
I wrote up this javascript and have no compiler errors, but when i walk i don't hear any footstep sounds. What's wrong? I tagged the objects correctly too.
var AudioTimer : float = 0;
var ConcreteSound: AudioClip;
var MetalSound: AudioClip;
function Update () {
if(AudioTimer > 0){
AudioTimer -= Time.deltaTime;
}
if(AudioTimer < 0){
AudioTimer = 0;
}
}
function OnControllerColliderHitt (col: ControllerColliderHit){
if(col.gameObject.CompareTag("concrete") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
Input.GetAxis("Horizontal") && AudioTimer == 0 ){
audio.clip = ConcreteSound;
audio.PlayOneShot(ConcreteSound);
AudioTimer = 0.5;
}
if(col.gameObject.CompareTag("metal") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
Input.GetAxis("Horizontal") && AudioTimer == 0 ){
audio.clip = MetalSound;
audio.PlayOneShot(MetalSound);
AudioTimer = 0.5;
}
}
Answer by sparkzbarca · Mar 27, 2013 at 05:51 PM
OnControllerColliderHitt 2 t's?
This is what i have, stll doesnt work
var AudioTimer : float = 0;
var ConcreteSound: AudioClip;
var $$anonymous$$etalSound: AudioClip;
var isWalking: boolean = false;
var controller : CharacterController = GetComponent(CharacterController);
function Update () {
if(AudioTimer > 0){
AudioTimer -= Time.deltaTime;
}
if(AudioTimer < 0){
AudioTimer = 0;
}
}
function OnControllerColliderHit (hit: ControllerColliderHit){
if(hit.gameObject.tag == ("concrete") && Input.GetAxis("Vertical") && AudioTimer == 0 && controller.isGrounded ||
Input.GetAxis("Horizontal") && AudioTimer == 0 && controller.isGrounded ){
Debug.Log ("isWalking");
isWalking = true;
audio.clip = ConcreteSound;
audio.PlayOneShot(ConcreteSound);
AudioTimer = 0.5;
}
else
{
isWalking = false;
audio.Stop();
}
if(hit.gameObject.tag == ("metal") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
Input.GetAxis("Horizontal") && AudioTimer == 0 ){
Debug.Log ("isWalking");
isWalking = true;
audio.clip = $$anonymous$$etalSound;
audio.PlayOneShot($$anonymous$$etalSound);
AudioTimer = 0.5;
}
else
{
isWalking = false;
audio.Stop();
}
}
Answer by fafase · Mar 27, 2013 at 05:57 PM
This is not going to work anyway, the character controller is a capsule over the whole character so it won't do what you expect. It does not collide the feet. You may want to use isGrounded instead to check if you are ...grounded.
All you need is to play a looping footstep sound while walking:
if(Input.GetAxis("Vertical")&& controller.isGrounded){
//Movement
audio.Play
}else
audio.Stop();
This is simplified version. Make sure your audio is looping. That could do it. controller stands for the reference to your character controller.
No capsule no character controller. $$anonymous$$eep the capsule but do not use it for the purpose of footstep sound. I can help you more than that...you are heading the wrong way trying to do your sound system into the collision function.
Your answer
Follow this Question
Related Questions
Footstep Audio Check Collider Hitting Floor 1 Answer
Footsteps script not working 2 Answers
Random Audioclip. No Repeat ?? 1 Answer
Playing audio when a button is clicked? 1 Answer
Audio loop after time 2 Answers