- Home /
Footstep sounds not coming up when walking? (MOBILE)
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();
}
}
What parts work, and what doesn't work? What kind of debugging have you done so far?
$$anonymous$$eep an eye out for 'Advanced Footstep System' co$$anonymous$$g soon to an Asset Store near you. http://bit.ly/1dENxco
#pragma strict
@script RequireComponent( AudioSource )
@script RequireComponent( CharacterController )
var walkSounds : AudioClip[];
var walkAudioSpeed : float = 0.7;
var walkAudioTimer : float = 0.0;
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);
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded && controller.velocity.magnitude > 0.2)
{
audio.Stop();
audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
audio.Play();
walkAudioTimer = 0.0;
}
if (controller.velocity.magnitude < 0.2)
{
walkAudioTimer = walkAudioSpeed;
audio.Stop();
}
}
I've changed up the code here a little bit, but it's the same concept and I'm still getting some sort of weird static sound...
Answer by DaveA · Feb 11, 2014 at 07:04 AM
Try this: Advanced Footstep System
FYI, my virus scanner shows this as a suspicious site. Are you sure about the link?
Answer by supernat · Jan 31, 2014 at 07:08 AM
In your Update method, you are stopping and restarting the sound every frame it appears. You should wrap your code that starts the sound playback with a check to see if the sound is not playing first. And if it is not playing, start the new random sound.
Answer by sumeetkhobare · Feb 11, 2014 at 07:43 AM
#pragma strict
@script RequireComponent( AudioSource )
@script RequireComponent( CharacterController )
var walkSounds : AudioClip[];
var walkAudioSpeed : float = 0.7;
var walkAudioTimer : float = 0.0;
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);
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded && controller.velocity.magnitude > 0.2)
{
//EDITED CODE
var flag = false;
for(var ws :AudioClip in walkSounds)
{
if(audio.isPlaying && audio.clip == ws)
{
flag = true;
break;
}
}
if(!flag)
{
audio.Stop();
audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
audio.Play();
walkAudioTimer = 0.0;
}
if (controller.velocity.magnitude < 0.2)
{
walkAudioTimer = walkAudioSpeed;
audio.Stop();
}
}
See if this works.. and mark as solved if it does.
Your answer
Follow this Question
Related Questions
Footstep Audio Not Working? 1 Answer
Footsteps Script for Running and Walking 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I fix audio loop delay 2 Answers
Footstep Script Not Working 2 Answers