Controling Animation position/frame

I am wondering if there is a way to control what position an animation is at?

What I mean by that if I were to have a animation that takes place for 2 seconds of time in the animator. I would like to be able to change the speed of the animation based on a variable.

So lets say the variable can be an int between 1-100. The animation would start when the var is 1 and end when the var is 100?

So if the var was a number bewteen 1-200 it would take twice as long to finish. I am looking to make an animation that will take place from when the object moves from point A to point B. If it takes 2 seconds to get from A to B then it plays at a speed it ends at 2 seconds. If it takes 10 seconds to go from A to B then it would take 10 seconds play the animation.

Anyone know how to do so?

1 Like

Are you using mecanim or legacy? There are ā€˜speed’ fields for both, but I can provide specific examples if you wish

I think I would be using legacy. Im not opposed to macanim. Haven’t dove into macanim much as of yet. Which ever way is the ā€œbestā€ approach. Im early on in development so no major rewrite or anything. I am aware of the speed field, but just dont understand how to use that to accomplish it.

Just to add, I would imagine since mecanim is a ā€œstandard featureā€ of unity, I might be best off going that route. It’s there for a reason, and I assume the flexibility is quite extensive. The little I’ve used of mecanim thus far makes me hesitent, although if it is worth it, then I should take the time to learn.

Mecanim is basically a state machine that animates objects with each state and transition. It will automatically blend animations together and keep everything smooth and glitch-free, which is very neat. Once you’ve familiarised yourself with the system (plenty of tutorials etc. exist) take a look at the API docs, and you’ll find the relevant code that’ll get you the animation speed, and the position within the current state/transition.