@blinkk/degu
    Preparing search index...

    Function lerp

    • Linear interpolate from start to end given amount.

      mathf.lerp(0, 1, 0)   ---> 0
      mathf.lerp(0, 1, 0.2) ---> 0.2
      mathf.lerp(0, 1, 0.5) ---> 0.5
      mathf.lerp(0, 2, 0.5) ----> 1
      mathf.lerp(25, 79, 0.2) ----> 35.8

      Lerp can be used for various things. See [[mathf.getValueInRangeByProgress]] which is an alias of lerp.

      Lerp can also be used for animations. If you were doing the old school:

      onRafLoop() {
      // Update the position by 20% of the distance between position and target.
      position.x += (target.x - position.x) * 0.2;
      }

      this can be replaced with:

      onRafLoop() {
      // Same thing. Update the position by 20% of the distance between
      // position and target on each raf loop. This has the effect of
      // tweening in the position to the target.
      position.x = mathf.lerp(position.x, target.x, 0.2);
      }

      Parameters

      • value1: number

        The start of the range to lerp.

      • value2: number

        The target of the range to lerp.

      • amount: number

        A value between 0-1 representing the progress of the lerp.

      Returns number

      The interporalated value.