using UnityEngine;

namespace ScrambleKit.Hits
{
    [RequireComponent(typeof(Rigidbody2D))]
    public class KnockBackUpAndAway : MonoBehaviour
    {
        public float UpwardFactor = 1.25f;
        private Rigidbody2D rb2;

        void TakeHit(HitInfo hit)
        {
            Vector2 knockSpeed = hit.Direction * hit.KnockBackPower;
            float xdir = (knockSpeed.x > 0) ? 1 : -1;
            Vector2 dir = new Vector2(xdir, UpwardFactor).normalized;

            Vector2 knockForce = rb2.mass * dir * knockSpeed.magnitude;
            rb2.AddForce(knockForce, ForceMode2D.Impulse);
        }

        void Start()
        {
            rb2 = GetComponent<Rigidbody2D>();
        }
    }

}