Why does this Lerp act like a time when going to a destination, but when going back it acts like a percentage?

First of all I apologise for not having the code formatted correctly, a screenshot is what I have.

For background, we’re making a 3d endless runner where the ground is what is moving, the character just jumps to different lanes and then back to the middle on keyup.

When he jumps forward, the movement is smooth just like I want. On his way back on keyup, he just teleports if the final value is 1. If it’s .5 like it is on keydown, he goes half way.

I’ve tried so many things like clamping and move towards but I’m just not sure what to do after 5 days of trying to fix it.

156085-received-581818266016213.jpeg

First of all that’s not how Lerp works. Here is the documentation, which you should have read before posting: Unity - Scripting API: Vector3.Lerp

A good way to do this will be with Coroutines.

Here is a simple example how this might work: (Haven’t tested)

void Update()
{
    if (Input.GetKeyDown(KeyCode.W))
    {
        StartCoroutine(JumpAnimation(1f));
    }
}

private IEnumerator JumpAnimation(float time)
{
    for(float t=0; t<=1; t+= 0.1f)
    {
        transform.position = Vector3.Lerp(transform.position, targetPos, t);
        yield return new WaitForSeconds(0.1f * time);
    }
    yield break;
}