I have successfully gotten a character to switch from an idle animation to a walking animation depending on if the character is walking or not. I also have been able to vary the speed of the animation to match the speed of the walk (thanks to looking at the 3rd person controller script).
What I am having trouble with is an animation where the walking motion is not smooth. The animation is (intentionally so) lurching and jerking. I have been having trouble getting the animation to sync up with the movement speed where it does not just look like the character is gliding across the ground.
The only solution I have thought of is to basically modify the velocity based on where the animation is. I am thinking of having the script stop motion during the 'lurch' and then when the animation moves on, continue motion again.
My question is just that if people have a suggestion on a better way to do this? Are there other (better) approaches for syncing the timing between translations and animations?
The better way to do this (or rather the way I would have done it in the first place) is to make the slowdowns occur in the animation itself, making the lurching character actually fall back a little from the origin point to signify that he's having trouble moving forward. This way you can maintain a constant speed but make it appear like he is lurching.
This is hard to describe, but for instance, let's say you have a standard walk cycle, a natural, normal walk cycle.
You typically animate this on the origin point completely.
For a zombie-like stumble, you might have to "simulate" ground moving beneath him. I recommend putting a texture on a plane and moving it under the character's feet while you animate, and try to match the lurching walk to the placement of the ground, even if you sometimes have to move the character a little backward/forward from the origin due to the irregularity of the walk cycle. This would look really weird as he stands still, but should look perfectly correct when he's actually walking in-game and moving.