- Home /
SmoothDamp won't reach its target
I've been bashing my head for a while on this. Here's what I've managed to rule out:
-The CoRoutine is called only once.
-The while loop is constant, yet doesn't crash.
-The "percentage" float jitters around 0.2F
Here's the code:
IEnumerator MoveTo(Vector3 endPosition)
{
Vector3 startPosition = transform.position;
Vector3 currentPosition = startPosition;
float smoothTime = timer;
float vel = 0.0F;
float percentage = 0;
// yield return new WaitForSeconds(delay);
while (percentage < 1)
{
percentage = Mathf.SmoothDamp(0F, 1F, ref vel, smoothTime);
print (Time.time);
currentPosition = Vector3.Lerp (startPosition, endPosition, percentage);
transform.position = currentPosition;
yield return 0;
}
}
Comment
Best Answer
Answer by robertbu · Jul 05, 2013 at 02:20 PM
You are misusing SmoothDamp(). The first parameter should be the current percentage. The last is the time it should take to reach the target. Replace line 5 with this:
percentage = Mathf.SmoothDamp(percentage, 1.0f, ref vel, 0.75f);
$$anonymous$$an... I can't believe I missed that. Thanks!
If you were used to using Lerp(), then you attempt makes sense. SmoothDamp() is a different kind of beast.