Hello everyone! I seem to be in a a bit of trouble…
I’ve changed up the walking script(s) that apply to PC controls (WASD). I’ve tried to have it to where if the Player’s velocity is anything higher than 0.0, then the walking audio would start. The thing is, there is an audio that plays when I walk, but it’s VERY FAST and it sounds like the sound is having a seizure. Anybody has a clue what I did wrong in this script?
#pragma strict
@script RequireComponent( AudioSource )
@script RequireComponent( CharacterController )
var walkSounds : AudioClip[];
var walkAudioSpeed : float = 0.7;
private var walkAudioTimer : float = 0.0;
var isWalking : boolean = false;
var walkSpeed: float = 8; // regular speed
var walkBackwardsSpeed: float = 8;
var walkSidewaysSpeed: float = 8;
private var controller: CharacterController;
function Start()
{
controller = GetComponent(CharacterController);
}
function Update()
{
var overallSpeed : float = controller.velocity.magnitude;
var velocity: Vector3;
var horizontalVelocity : Vector3 = controller.velocity;
horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
if ( controller.isGrounded && overallSpeed > 0.2 )
{
audio.Stop();
audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
audio.Play();
walkAudioTimer = 0.0;
}
else
{
walkAudioTimer = walkAudioSpeed;
audio.Stop();
}
}