- Home /
Why is my SmoothDamp taking four times longer to finish than it should?
This takes 4.6 seconds to complete. I want it to take 1.0 seconds - like I put in the function.
cur, to, and vel are not altered anywhere.
What have I done wrong?
#pragma strict
var from : float;
var to : float = 10;
var time : float = 1;
private var vel : float;
private var cur : float;
private var amntTime : float;
function Start () {
cur = from;
vel = 0;
}
function Update () {
amntTime += Time.deltaTime;
cur = Mathf.SmoothDamp(cur,to,vel,time);
if ( Mathf.Abs(cur-to) < 0.01 ) {
Debug.Log("Took " + amntTime);
gameObject.active = false;
}
}
I was using deltaTime, which has the same results as this convoluted thing. Just trying to see if somehow the coroutine was getting the wrong deltaTime.
Right, it is. It's a consistent ratio of time taken - if I tell it to take one second, it takes 4.6; if I tell it to take 0.25 seconds, it takes 1.~ seconds. It's about 4x longer than it should. It seems hilarious to me but I also wanna make it work.
This is running in a static coroutine (object.StartCoroutine(staticFunction()), if that matters.
I've always considered that time to be nothing to do with seconds! It says in the doc "approximate time" - never seemed particularly relevant to the time in seconds to me.
It says approximate cause it's no precise. It can't justify an 4x difference.
Or perhaps because the documentation author didn't understand what algorithm was being used - given the docs are very poor in some places I wouldn't be surprised.
Answer by GibTreaty · Oct 27, 2012 at 02:26 PM
SmoothDamp looks like it uses Time.deltaTime internally or some other method of keeping the smoothing consistent over each frame. Try replacing "Time.time - lastTime" with something constant and it should work. Like putting a 1 should smooth it for one second. I could be wrong but I have used SmoothDamp before and noticed that putting Time.deltaTime in that parameter slot is pointless.
Your answer
Follow this Question
Related Questions
SmoothDamp smoothTime ignored! 1 Answer
SmoothDamp keeps changing back 0 Answers
When to use Time.deltaTime? 3 Answers
Transform localPosition on time 2 Answers
Working with probability over time 3 Answers