using Assets.Source.Constants;
using UnityEngine;

namespace Assets.Source.Core.Gameplay.Topdown
{
    public class UIDestinationArrow : MonoBehaviour
    {
        public Transform CharacterRoot;
        public Transform Target;
        public Transform ArrowRoot;
        public Animator Animator;

        public float DirOffsetMult = 20;
        public float DirOffsetLimit = 100;
        public float DeactivationDist = 2;

        void FixedUpdate()
        {
            if (Target == null)
                return;
            var dir = Target.transform.position - CharacterRoot.position;
            ArrowRoot.localPosition = (dir* DirOffsetMult).ClampTop(DirOffsetLimit);
            ArrowRoot.transform.rotation = dir.DirToRotation();
            Animator.SetBoolIfAvailable("Active", dir.magnitude > DeactivationDist);
        }
    }
}
