Function lerp

  • Performs linear interpolation between the current and target values using an ease factor.

    Linear interpolation (LERP) calculates the intermediate value between two values (current and target) based on a given easing factor.

    Parameters

    • current: number

      The current value or starting point.

    • target: number

      The target value or end point.

    • factor: number

      The factor, typically between 0 and 1, which controls how fast the interpolation happens. A value closer to 0 makes the change slower, and a value closer to 1 makes it faster.

    • approximationLeft: number = 0

      The threshold within which the difference between current and target is considered negligible, and the function returns the target value directly.

    Returns number

    Example

    lerp(0, 1, 0.4); // => 0.4
    lerp(0.75, 0.8, 0.98); // => 0.799