- Home /
Footsteps, landing sounds when jumping (javascript)
I'm using a simple first person controller for teaching a class in game audio. I'm using Unity 4 since the school hasn't updated to 5 yet. The script I've been using has worked fine: it gives me a variable that allows me to adjust the footstep speed:
var footStepSounds : AudioClip[]; //array
var stepLength = 0.3;
function Awake () //this is so we load up the sounds right away
{
PlayFootstepSounds();
}
//at bottom:
function PlayFootstepSounds()
{
var controller : CharacterController = GetComponent(CharacterController);
while (true)
{
if (controller.isGrounded && controller.velocity.magnitude > 0.3)
{
audio.clip = footStepSounds[Random.Range(0, footStepSounds.length)];
audio.Play();
yield WaitForSeconds (stepLength);
}
else
{
yield;
}
}
}
However, when jumping, I would like to have a landing sound before the footsteps resume. I looked around the forums here and found a script that I modified:
var footStepSounds : AudioClip[];
var landSound : AudioClip;
var moveSpeed : float = 0.3;
private var hasJustLanded = true;
function Awake()
{
//PlayFootStepSounds();
}
function Start () {
}
function Update(){
PlayFootStepSounds();
}
function PlayFootStepSounds()
{
var controller : CharacterController = GetComponent(CharacterController);
var isMoving = Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d");
if (controller.isGrounded) {
if (isMoving) {
Debug.Log("I'm walking");
if (!audio.isPlaying) {
audio.clip = footStepSounds[Random.Range(0, footStepSounds.length)];
audio.Play();
yield WaitForSeconds (moveSpeed);
}
}
else if (audio.isPlaying)
{
audio.Stop();
}
if (!hasJustLanded) {
hasJustLanded = true;
Debug.Log("yo I just landed, where you at?");
AudioSource.PlayClipAtPoint(landSound, transform.position);
Debug.Log("BOOM");
}
}
else {
if (audio.isPlaying)
{
audio.Stop();
}
Debug.Log("yo check dis out am flyin! :D");
hasJustLanded = false;
}
}
The problem is that I can't adjust the moveSpeed, or rather my adjustments don't work. I'm fairly new to scripting, so apologies if this is really simple, but if anyone can help out I would greatly appreciate it!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612080023im_/https://answers.unity.com/themes/thub/images/avi.jpg)