using UnityEngine;

namespace ScrambleKit.Move
{
    public static class RigidBody2DExtensions
    {
        public static void AccelTowardVelocityByAtMost(this Rigidbody2D rb, Vector2 targetVelocity, float maxAccelPerSec)
        {
            Vector2 deltaVel = targetVelocity - rb.velocity;
            float changePossible = Mathf.Min(deltaVel.magnitude / Time.fixedDeltaTime, maxAccelPerSec);

            Vector2 accel = changePossible * deltaVel.normalized;
            Vector2 forceAccel = rb.mass * accel;
            rb.AddForce(forceAccel);
        }

        //public static void XAxisAccelTowardVelocityByAtMost(this Rigidbody2D rb, Vector2 targetVelocity, float maxAccelPerSec)
        //{
        //    float deltaSpeed = targetSpeed - core.rb2.velocity.x;
        //    float changePossible = Mathf.Clamp(deltaSpeed / Time.fixedDeltaTime, -MoveAcceleration, MoveAcceleration);


        //    Vector2 deltaVel = targetVelocity - rb.velocity;
        //    float changePossible = Mathf.Min(deltaVel.magnitude / Time.fixedDeltaTime, maxAccelPerSec);

        //    Vector2 accel = changePossible * deltaVel.normalized;
        //    Vector2 forceAccel = rb.mass * accel;
        //    rb.AddForce(forceAccel);
        //}

    }
}