Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by komodor · Jan 08, 2014 at 09:40 AM · mecanimtweenblendtreesetfloat

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by GameVortex · Jan 08, 2014 at 10:03 AM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image komodor · Jan 08, 2014 at 10:44 AM 0
Share

i actually do update it every frame now, i just wasn't sure if it's the efficient way

thank you very much sir!!!

avatar image GameVortex · Jan 08, 2014 at 11:13 AM 1
Share

No problem. =)

You are not supposed to close questions when they are answered though. You should mark the question specifically answered by pressing the button next to the answer that best worked for you.

avatar image MonoKoschi · Oct 15, 2015 at 03:05 PM 1
Share

Thanks for this explanation. The Unity documentation is a tad short on this function.

I do use a slightly extended version of this code in my current project:

 float dampTime = $$anonymous$$athf.Clamp(input.horizontal.since + 0.1f - Time.time, 0f, 0.1f);
 animator.SetFloat("Speed", $$anonymous$$athf.Abs(input.horizontal.value), dampTime, Time.deltaTime);

This way the given value is reached after 0.1 seconds. Without this the animator value will crawl nearer to the given value every frame, but will never reach it.

We're using the two lines above to feed the speed input to the animator. Inside it we use a blendtree for walking animations. These animations have events for the footfalls which cause the sound to be played.

Now when the value is very small the character won't move, but the animations in the blendtree still run, causing the footfall sound to be played even though the character is not moving. Which is what happened with the original code seen above.

Now the value of "Speed" actually is 0 after 0.1 seconds and no footfall sounds are played.

avatar image
4

Answer by Stuart Harrison · Oct 23, 2015 at 03:28 PM

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: http://www.thefreedictionary.com/dampen

"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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
4

Answer by unityBerserker · Oct 29, 2018 at 12:57 PM

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 ();
         }
     }
 
 }


alt text


setfloat-z-damp2.png (35.4 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

(Mecanim issue) How to get several Walk Cycle Stop Animation with proper foot placement and smooth transition? 1 Answer

Is it possible to tween with mecanim like with iTween, GoKit...? 0 Answers

SetFloat Shader Value question/issue 0 Answers

Battlerite-lookalike walk animations 0 Answers

Mecanim Character Barrel Roll 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges