Function criticallyDamped

Returns the new position and velocity for a critically damped user-driven spring state toward a current target position.

v1.2.0

  • Parameters

    • settings: {
          dt: number;
          l?: number;
          lag: number;
          lTarget: number;
          precision?: number;
          v?: number;
      }
      • dt: number

        Time step in milliseconds since the last call. Must be small for the returned values to be meaningful.

      • Optionall?: number

        Current position (starting or one returned by previous call).

      • lag: number

        Lag in milliseconds (how long it should take for it to reach the final position). Must be positive.

      • lTarget: number

        Target final position.

      • Optionalprecision?: number

        Number of decimal places to round position to in order to determine when it's "done".

      • Optionalv?: number

        Current velocity (returned by previous call).

    Returns { l: number; v: number }

    Updated position and velocity