Why is lerp sending my player to the moon? (solved)

Real basic lerp that I just applied to act as acceleration for my player controller is launching the player instantly out of bounds.

worked perfectly fine before adding the lerp.

And I have the acceleration set to 0.5 and 0.1

Doesn’t fly off when its a whole number, strangely.

    private void UpdateMovement()
    {
        movementInput = movement.action.ReadValue<Vector2>();
        if (isGrounded) movementHeading = Vector2.Lerp(movementHeading, movementInput, groundAcceleration);
        if (!isGrounded) movementHeading = Vector2.Lerp(movementHeading, movementInput, airAcceleration);
        movementHeading *= movementSpeed;
        movementHeading.y = 0;
        if (movementHeading.x > 0)
        {
            if (!isFacingRight) transform.rotation = Quaternion.Euler(0, 0, 0);
            isFacingRight = true;
        }
        if (movementHeading.x < 0)
        {
            if (isFacingRight) transform.rotation = Quaternion.Euler(0, 180, 0);
            isFacingRight = false;
        }
    }

    private void ApplyMovement()
    {
        Vector3 appliedMovement = new Vector3(movementHeading.x, movementHeading.y, 0);
        appliedMovement *= Time.fixedDeltaTime;
        if (isGrounded) appliedMovement += hit.point;
        if (!isGrounded) appliedMovement += transform.position;
        myRigidbody.MovePosition(appliedMovement);
    }

Thanks in advanced.

Well, what do you think this line would do each frame?

You keep movementHeading between frames but each time you multiply it with movementSpeed. While the lerp may “try” to get it closer to your input values, this line will multiply the current value exponentially over time.

You may want to use your movementSpeed at the time you apply the movement to the rigidbody.

1 Like

D’oh!

That would do it.

I’ve been pulling my hair out on this for over and hour.

Thanks!

1 Like