SmoothDamp breaks if I change the smoothTime value

Hi all,

I’m running into this issue when I change the Mathf.SmoothDamp smoothTime value.
If I adjust the smoothTime value midway through a movement, the smoothdamp will reach its target with a hard clunk rather than smooth ease in.

Does anyone know why that might happen?
I really need to be able to change this over time but it’s looking really bad at the moment with these hard clunks.

    public Transform cube;
    public float target;
    [Range(0,2)]public float smoothTime;
    public float refVEL;
   
    IEnumerator Start()
    {
        target = 20;
        smoothTime = 0.5f;
        yield return new WaitForSeconds(1);
        smoothTime = 3f;
    }
   
    void FixedUpdate()
    {
        var tempPos = cube.position;
        tempPos.x = Mathf.SmoothDamp(tempPos.x, -target,  ref refVEL, smoothTime);
        cube.position = tempPos;
    }

Thanks,
Pete

Hey Petey, have you considered just using something like LeanTween or iTween or DOTween from the asset store? Those packages all do this stuff and like 1000x more.

For tracking this down, simplify everything and then do the good old Debug.Log() everywhere trick.

I haven’t used smoothdamp much, I always just Lerp() towards my targets, which moves FAST at first, but then eases to a stop nicely.

Lerping to smooth things out:

Thanks kurt!

iTween and the likes are great, but for my purpose I feel this was more appropriate as I needed it to be smoothing continuously. I’m not too sure why I settled on smoothdamp though so I’ll have a look at those examples and see if I can get what I’m after with Lerp.

1 Like