- Home /
How to use Mathf.Lerp and Mathf.InverseLerp???
Could u tell me how to use Mathf functions to smooth a value(in this case an animation weight)based on the inputs??? Thanks
The docs contain examples: http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$athf.Lerp.html
What aspect of these functions are you having trouble with?
Answer by save · Jun 30, 2011 at 09:51 AM
It's not clear what your agenda with altering weight is, you might be able to use crossfade between states instead:
yourAnimation.blendMode = AnimationBlendMode.Additive;
animation.CrossFade("yourAnimation", 0.1);
Have a look at how it's possible to do crossfading between different animation-states here (using Animation Layers). The Character Animation is very helpful from the Manual and also see the Script Reference for Animations.
There are a couple of Mathf functions you could use for interpolating values,
yourAnimation.weight = Mathf.SmoothStep(0.0, 1.0, Time.time);
yourAnimation.weight = Mathf.SmoothDamp(yourAnimation.weight, 1.0, 0.0, 0.3);
yourAnimation.weight = Mathf.Lerp(yourAnimation.weight, 1.0, Time.time);
Then you could use an if-statement to just go between min and max:
if(Input.GetAxis("yourAxis")){
yourAnimation.weight = Mathf.Lerp(yourAnimation.weight, 1.0, Time.time);
}else{
yourAnimation.weight = Mathf.Lerp(yourAnimation.weight, 0.0, Time.time);
}
Have a look at Mathf in the script reference for more details.
Does any of these solutions seem helpful for your situation?
thank u, this is very helpful, fortunately s.one answered to me!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Lerp animation duration 1 Answer
Update iTween Path at Runtime 1 Answer
Mathf.Lerp not working as expected 2 Answers
Animation vs. Lerp / MoveTowards Performance Comparison 1 Answer