using OpenTK.Mathematics;

namespace DoomDeathmatch.Component.Util;

public class DragComponent : Engine.Scene.Component.Component
{
  public float Drag { get; set; } = 1f;
  public Vector3 Coefficient { get; set; } = Vector3.One;

  private RigidbodyComponent _rigidbody = null!;

  public override void Awake()
  {
    _rigidbody = GameObject.GetComponent<RigidbodyComponent>()!;

    ArgumentNullException.ThrowIfNull(_rigidbody);
  }

  public override void Update(double parDeltaTime)
  {
    _rigidbody.AddForce(-Drag * (_rigidbody.Velocity * Coefficient));
  }
}