Animation Speed

I was wondering if anyone knows how I can have the speed of my animation match the speed that my character moves?

I found a post on it somewhere but for the life of me can’t find it again :stuck_out_tongue:

for example if my players actual speed is 5 the animation (run) would match, then later if I increase the speed to 7 the animation speed would match. It was an excellent post which sadly I cant find anymore and forget how to do it :frowning:

Alright, I remembered… :slight_smile:

Im not sure if this is the correct way or not but it seems to be working if there is a better way please let me know heres the code.

moveSpeed is the speed that my player actually moves modSpeed is the variable I use to match the run animation with the actual moveSpeed. It takes a little tweeking of the modSpeed to match the actual speed (moveSpeed) but once its looking good there’s no need to change the modSpeed again and anytime you change the moveSpeed the animation speed will now match :slight_smile: If thats understandable?

var moveSpeed = 3; //move speed
var modSpeed : float = 0.0;

function Start ()
{
   animation.wrapMode = WrapMode.Loop;
   animation["run"].speed = moveSpeed * modSpeed; //THIS IS THE KEY :)
   animation.CrossFade("run");
}