- Home /
Having trouble with PlayClipAtPoint and Mecanim Curves
Hello everyone.
My player is setup with 2 scripts relevant to this issue: one is just a list of public audio clips (PlayerSounds.cs), the other is my character controller script (PlayerController.cs).
My controller script has an audio management function, like so:
void AudioManagement()
{
footSteps = anim.GetFloat("FootStep");
if(footSteps > 0.5)
AudioSource.PlayClipAtPoint(playerSounds.footStepSound, transform.position);
}
The footSteps variable is a public float, and is linked to the animation clip's curve, which for all walks/runs has 2 peaks at the value of 1. The peaks are synced to the foot/ground contact frame.
Now here's the funny bit: the sound only plays whenever it wants to. Sometimes I get 3 footstep sounds in a row before it goes silent for a few frames, then I get 1 or 2, then again a break in play, and on and on. Usually the silent treatment is longer (in seconds) than the cumulative duration of the played sounds, if that makes sense.
The audio clip's duration exceeds the time in between the peaks, meaning the sounds should overlap. And sometimes they do, only without any apparent logic.
Oh and the Audio Management function runs during FixedUpdate. Switching Fixed for regular Update didn't improve things.
If all else fails I will try the OnTriggerEnter solution, but that involves adding triggers to both feet and burdening the scene. I'd like to stick to a (working!) Curve/PlayClipAtPoint setup.
Any help/ideas appreciated, thanks in advance.
Answer by indieman · Jul 15, 2014 at 07:54 AM
The OnTriggerEnter solution works perfectly. But it's not as elegant. Oh well.