Could u tell me how to use Mathf functions to smooth a value(in this case an animation weight)based on the inputs???
Thanks
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?