- Home /
What is the purpose of the deltaTime parameter in animator.SetFloat
Why does animator.setFloat take deltatime as an input, and thusly have it available as a parameter in the function? This is a value that can easily be accessed from anywhere with Time.deltaTime, right?
This seems redundant and unnecessary.
Answer by tanoshimi · Oct 15, 2014 at 04:28 PM
You don't have to provide Time.deltaTime to SetFloat - if you want to just set a float value instantly, call
animator.SetFloat("speed", _speed);
However, there is an overload of SetFloat that allows you to smoothly change a float over time (basically a lerp), whose function signature is:
void SetFloat(int id, float value, float dampTime, float deltaTime);
This changes a float to value
over dampTime
amount of time, where deltaTime
is the amount of time that's elapsed since the last time the function was called. It doesn't automatically retrieve Time.deltaTime for you because if you were calling this method from FixedUpdate, you'd want to use, say, Time.fixedDeltaTime instead, or you might want to calculate a more elaborate timestep function.
Below is post with explanation how work this version of SetFloat()
void SetFloat(int id, float value, float dampTime, float deltaTime);
Your answer

Follow this Question
Related Questions
Animation Vs Animator 2 Answers
How to change the speed of an animation? 1 Answer
2D Animation does not start 1 Answer
How to disable an Animator component? 1 Answer
Moving an animated object's animator instead of the object? 0 Answers