Lerp a float ?

How would i be able to lerp this ?

transform.position = new Vector3(ladderPos, transform.position.y, Time.deltaTime *toladderinseconds);

no lerp takes place, no toladderinseconds takes place.
it just snaps to the ladder.
Maybe using Vector3.Lerp, but it don`t allow floats ?

My full code is this for anybody intrested

    private void LadderClimbLogic()
    {
        float laddtime = 3f;
        if (isClimbing && isLadder)
        {
            rb.gravityScale = 0f;
            rb.velocity = new Vector2(rb.velocity.x, yAxis * climbSpeed);
            transform.position = new Vector3(ladderPos, transform.position.y, Time.deltaTime *laddtime);
            rb.constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePositionX;

            if (xAxis > 0 && Input.GetButtonDown("Interaction") || xAxis < -0 && Input.GetButtonDown("Interaction"))
            {
                {
                    isClimbing = false;
                    IsClimbingMove = false;
                    isLadder = false;
                    canMove = true;
                    isJumping = true;
                    isWalking = false;
                }
            }
        }
        else
        {
            rb.gravityScale = startingGravity;
            rb.constraints &= ~RigidbodyConstraints2D.FreezePositionX;
            if (canMove)
            {
                canDash = true;
            }
        }
    }

Unity has documentation on how it works and how you’re supposed to use it.

Do you not know that if you go to the API docs (Script Reference) and just type “lerp” in the search box you’d find it super quick?

First item listed:

If you don’t want to use the Mathf version for some reason, a float lerp is just this:
lerp = inputA * t + inputB * (1 - t)
for t between 0 and 1.

1 Like