Hello, I’ve been reading how to add footsteps sound and sounds in general to the game and think I’ve got about the right idea but there are certain sound that don’t play as they should, This is the script for a 2d like Castlevania or Dust Elysian Tale.
if (Input.GetKey(KeyCode.RightArrow) && !Playing_Left && Milu_Grounded && !Ground_First_Press && Skip_Next_Movement && !Milu_Airborne && !Facing_Left){
Vector3 right = transform.TransformDirection(Vector3.right);
if (rigidbody.velocity.x < (Movement_Speed_Walk/3.7f) && !Milu.IsPlaying("Crouch")){
rigidbody.AddForce(right * (Movement_Speed_Walk/3.7f) , ForceMode.Impulse);
}
if (!Milu.IsPlaying("Walk")) {
Milu.Play("Walk");
Walking_Milu = true;
Idle_Milu = false;
Playing_Right = true;
Facing_Left = false;
Crouching_Milu = false;
Milu_Landing = false;
Space_Bar_Hold = false;
Running_Milu = false;
Skip_Next_Movement = true;
Time_Lapse_Walk = Time.time; // Esta linea crea un margen de tiempo entre el tiempo real y el "Time_Lapse_Walk"
// para revisar si se esta dentro de este margen de tiempo y se detecte el double-tap
if(Walking_Milu && Milu_Grounded){
audio.volume = 0.4f;
audio.clip = Walking_HardFloor_Sound;
audio.Play();
audio.loop = true;
}
}
}
/* Este pedazo de aqui invierte el "!Ground_First_Press && Skip_Next_Movement" a "Ground_First_Press && !Skip_Next_Movement"
* cuando se suelta la techa de la flecha derecha, para que cuando se vuelva a presionar la flecha se revisen y se pueda correr*/
if (Input.GetKeyUp(KeyCode.RightArrow) && Facing_Left == false){
Skip_Next_Movement = false;
Ground_First_Press = true;
Walking_Milu = false;
Milu_Landing = false;
//audio.Stop();
}
/* Aqui ocurre practicamente lo mismo que en Walk exceptuando que esto se ejecuta si se esta dentro del margen de tiempo
* previamente creado y "!Ground_First_Press && Skip_Next_Movement" estas invertidas, se aplica una fuerza con otros valores
* y se corre la animacion "Run"*/
if (Input.GetKey(KeyCode.RightArrow) && ((Time.time - Time_Lapse_Walk) < Time_Lapse_Run && Ground_First_Press && !Skip_Next_Movement && !Playing_Left && !Milu_Airborne) || (Running_Milu && !Playing_Left && !Milu_Airborne)){
Vector3 right = transform.TransformDirection(Vector3.right);
if (rigidbody.velocity.x < (Movement_Speed_Walk*0.9f) && !Milu.IsPlaying("Crouch")){
rigidbody.AddForce(right * (Movement_Speed_Walk*0.9f) , ForceMode.Impulse);
}
Milu.Play("Run");
Walking_Milu = false;
Idle_Milu = false;
Facing_Left = false;
Playing_Right = true;
Crouching_Milu = false;
Milu_Landing = false;
Space_Bar_Hold = false;
Running_Milu = true;
Ground_First_Press = true;
Skip_Next_Movement = false;
Time_Lapse_Walk = Time.time;
if(Running_Milu && Milu_Grounded){
audio.clip = Running_HardFloor_Sound;
audio.Play();
audio.loop = true;
}
}
// Comments are in spanish, my language so I dont forget what I did there
It starts playing like it should, the walking sounds plays but when the character runs it plays some sort of static while its grounded, yet if I jump while running the sound plays correctly, I really dont understand why.
Thanks.