using System.IO.Pipes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class PlayerJump : MonoBehaviour
{
    [Header("Jump Property")]
    public float DefaultJumpPower = 10f;
    [SerializeField] private float _minJumpPower;
    [SerializeField] private float _jumpPower = 5f;
    public float JumpPower { get => _jumpPower; set => _jumpPower = Mathf.Clamp(value, _minJumpPower, DefaultJumpPower); }

    private Rigidbody _rigid = null;
    private Animator _anim = null;
    // [Space(10f)]
    // [SerializeField] private Vector3 _minClamp;
    // [SerializeField] private Vector3 _maxClamp;

    private void Awake()
    {
        _rigid = GetComponent<Rigidbody>();
        _anim = GetComponentInChildren<Animator>();
    }

    private void Update()
    {
        // _rigid.angularVelocity = new (0, 0, _rigid.angularVelocity.z);
        // transform.rotation = Quaternion.Euler(0, 0, transform.eulerAngles.z);
        _rigid.inertiaTensorRotation = Quaternion.identity;
    }

    public void DefaultJump(Vector3 dir)
    {
        if(_anim != null)_anim.SetTrigger("Jump");
        // _anim.SetTrigger("Jump");
        _rigid.velocity = Vector3.zero;
        _rigid.AddForce(dir.normalized * JumpPower, ForceMode.Impulse);
    }

    public void CommonJump(Vector3 mousePos)
    {
        // if(mousePos.y >= transform.position.y) return;
        if(_anim != null)_anim.SetTrigger("Jump");
        Vector3 dir = (transform.position - mousePos).normalized;
        _rigid.velocity = Vector3.zero;
        _rigid.AddForce(dir * _jumpPower, ForceMode.Impulse);
    }
}
