using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class ExternalForceHandler {
  private Transform Transform;
  private Rigidbody Rigidbody;
  private List<Transform> TextList = new List<Transform>();

  public ExternalForceHandler(Transform transform) {
    Transform = transform;
  }

  private void Apply(Vector2 force) {
    Rigidbody.linearVelocity = force;
  }
}

public static class KnockbackUtility {
  public static void ApplyKnockback(MonoBehaviour context, Rigidbody2D rb, Vector2 direction, float force, float duration) {
    context.StartCoroutine(KnockbackRoutine(rb, direction.normalized, force, duration));
  }

  private static IEnumerator KnockbackRoutine(Rigidbody2D rb, Vector2 direction, float initialForce, float duration) {
    float elapsed = 0f;
    while (elapsed < duration) {
      float t = elapsed / duration;
      float currentForce = Mathf.Lerp(initialForce, 0f, t); // Linear diminishing force

      rb.linearVelocity = direction * currentForce;

      elapsed += Time.deltaTime;
      yield return null;
    }

    rb.linearVelocity = Vector2.zero;
  }
}



