damptime and deltatime in setfloat parameters

Please can somebody explain to me (cause I am not native english speaking person and i don’t get that DAMP means, cause all dictionaries i found are pointin to words like “wet” and no others) what DAMPTIME MEANS ? And why is there Time.deltaTime

Should I call the setFloat on update or just once ? Following the previous question:

question part 1:

I am trying to use 2D BlendTree in mecanim, and I would like to fade the float speed from 0 to 1, it’s accomplished by:

animator.SetFloat(“speed”, desiredSpeed, damptime, deltatime)
but I still don’t get what that mean, i’d understand that the damptime is time needed to finish the fade but why is the deltatime there? and how is it counted? if i put there

animator.SetFloat(“speed”, _speed, 0.1f, Time.deltaTime);
then it’s slow, for sure not 0.1 second, so I am not quite sure what parameters to put there to have 1/10 sec fade time

question part 2:

when I use:

animator.SetFloat("speed", _speed);

then it works, but does not blend smoothly

and when i use

animator.SetFloat("speed", 1f,1f,Time.deltaTime);

then it stops at speed 0.0196…

animator.SetFloat("speed", 1f,0.01f,Time.deltaTime); // 0.66
animator.SetFloat("speed", 1f,0.001f,Time.deltaTime); // 0.95
animator.SetFloat("speed", 1f,0.0001f,Time.deltaTime); // 0.99

so I am not quite sure

I am calling the SetFloat only once.

SetFloat with the dampTime is not an automatic function that will change the value over time for you after you have called it once. dampTime is the time you want it to take to get to the target value (sort of). While the deltaTime is the current frames deltaTime which is the time value the function bases its calculations on. The current deltaTime will be multiplied by the dampTime to create the smoothing.
So by calling the function once the float value will be smoothed based on one calculation of dampTime by the amount of deltaTime.

Basically it does something like this (approximate):

currentValue = Mathf.Lerp(currentValue, targetValue, deltaTime * dampTime);

This is just a linear interpolation which moves one value towards another value by a small amount. So by calling this once the currentValue has moved a little towards your targetValue.

The solution here is that you will have to call SetFloat every update to create the smoothing effect. Which makes the currentValue move towards the targetValue every frame.

Signature of SetFloat():

public void SetFloat(string name, // name of parameter
                      float value, //value of parameter we want to reach
                      float dampTime, 
                      float deltaTime); //how often we sample

To understand dampTime you must see graph below.


In this example I set dampTime to 1s.

So after 1s SetFloat() return 63% of value.

After 2s SetFloat() return 86% of value. ect.


If I set dampTime to 20s.

Then after 20s SetFloat() return 63% of value.

And After 40s SetFloat() return 86% of value. ect.


This script add to gameObject with Animator and change name of state in script (to name of state in your Animator)


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SetFloatWithDampTest : MonoBehaviour
{

	[SerializeField]AnimationCurve ac;
	Animator a;
	string paramName = "ZZZ";
	//parameter value we want to reach
	int value = 100;

	void Start ()
	{
		a = GetComponent<Animator> ();
		ac.AddKey (new Keyframe (0, 0));
	}

	// I use FixedUpdate to get readable graph of how value change
	// Use Update() or FixedUpdate() - depends how you use animations
	void FixedUpdate ()
	{
		a.SetFloat (name: paramName , 
			value: value, 
			//after this time we get 63% of value, after 2xdampTime we get 86% of value ect. - check graph
			dampTime: 1f,
			// how often we sample
			deltaTime: Time.deltaTime);


		AddKeysAndLogInfo ();
	}

	void AddKeysAndLogInfo ()
	{
		float percentage = a.GetFloat (paramName ) / value * 100;
		percentage = (float)System.Math.Round (percentage, 2);

		if (a.GetFloat (paramName ) != 0) {
		ac.AddKey (new Keyframe (Time.fixedTime, a.GetFloat (paramName )));
			Debug.Log (percentage + "%  : " + Time.time + "s");
		}

		// I pause aplication when value is appriximately 99% because SetFloat() have problem with reaching 100% of value
		if (percentage >= 99) {
			Debug.Break ();
		}
	}

}

For what it’s worth, for reference to @komodor, “damp” in this sense is a contraction (shortening) of “dampen”, in the second sense of the word here:

“2. To deaden, restrain, or depress”

It’s a word you might use to describe the job done by the suspension system on your car - that of smoothing out rough terrain (rapid changes in vertical position).

Hope that helps!