Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by exerion · Nov 17, 2015 at 03:12 AM · timelerptime.deltatimeslowsmoothdamp

SmoothDamp smoothTime ignored!

Hi :)

SmoothDamp.smoothTime is ineffective at controlling the duration of SmoothDamp. Has anyone had success using it?

In the following script SmoothDamp is set to reach it's target in 1 second...it's takes ~2.4 seconds. I know smoothTime is approximate but this amount of deviation makes SmoothDamp useless for a lot of applications.

Chuck this script on an object and and hit play. On the script toggle the 'StartSmoothDamp' bool and the SmoothDamp will run until it's within the defined threshold of the target value at which time it will log out how long the SmoothDamp took.

 using UnityEngine;
 using System.Collections;
 
 public class SmoothDamp : MonoBehaviour
 {
     [Range(0f,1f)]
     public float Current = 0f;
     private float target = 1f;
     public float Velocity;
     public float Duration = 1f;
     private float LastTime = 0f;
     public float Threshold = 0.05f;
     public bool StartSmoothDamp = false;
     
     void Update ()
     {
         if (StartSmoothDamp) {
             Current = Mathf.SmoothDamp (Current, target, ref Velocity, Duration);
             
             if (Mathf.Abs (Current - target) < Threshold) {
                 Debug.Log ("Duration: " + (Time.time - LastTime));
                 StartSmoothDamp = false;
             }
         } else {
             Current = 0f;
             Velocity = 0f;
             LastTime = Time.time;
         }
     }
 }

Thanks for reading :)

Comment
Add comment · Show 1
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 Suzuka91 · Feb 27, 2017 at 02:32 PM 0
Share

Did you find a solution? I'm having exactly the same problem, it's not working as expected

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by Zorkman · Nov 17, 2015 at 08:02 AM

Hi!

There might be some kind of serialization conflicts since you are initiating the variables during compile time and also having them public so they become serialized. I guess that you sometime entered the 2.4s in the editor and now it disregards the Duration = 1f you wrote in your class. I've had a similar problem a long time ago.

Also it seems that you are forcing the Current variable to stay between 0 and 1 using the Range() attribute. This seems like a very weird idea since the Current variable is not something that should be tweaked (and actually not public for any other use than so you can debug it). Instead if you want to limit the range of variables (which are not meant to be tweaked) I would use Mathf.Clamp()or Mathf.Clamp01.

TIP!

Instead of having a public bool that enables/disables your smoothdamp, make use of unity's enabled property and use the OnDisable/OnEnable functions to reset your variables. Here's a list of all messages a MonoBehaviour uses: http://docs.unity3d.com/ScriptReference/MonoBehaviour.html

Comment
Add comment · Show 2 · 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 exerion · Nov 19, 2015 at 05:45 AM 1
Share

Hi Zorkman :)

Thanks for your reply. This scripts sole purpose was to test SmoothDamp.

I'm pretty sure there are no serialization conflicts.

I simply used the Range() attribute so it was easy to visualise the value of Current.

Thanks for the tip. I used a bool so I could repeatedly set it while running in the editor to test different durations.

avatar image Zorkman exerion · Nov 19, 2015 at 09:47 AM 0
Share

Np :) Did you fix the problem? Another thing could be that maybe your Time.TimeScale is not 1.

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

33 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 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

Time.deltaTime not working correctly? 1 Answer

Flashlight Cooldown and Timer 1 Answer

How does DeltaTime handle game logic ? 1 Answer

When to use Time.deltaTime? 3 Answers

Mathf.Lerp happens instantly 2 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