I want you to modify the simulate projectile function:

*Start the parabolic movement at the initial transform. position
*The maximum height is reached at the middle of the trajectory
*End the movement in target, take into account target will move so the end destination is dynamic
*the longer the distance the arrow goes up, the shorter the distance the arrow goes down, the minimum height is a straight line with the target


using System.Collections;
using Game.Systems;
using UnityEngine;

namespace Game.ImprovedAI
{
    public class Arrow : MonoBehaviour
    {
        public float speed = 10f;
        public float maxHeightFactor = 0.5f; // Adjust the height of the projectile
        public float damageRange;
        public float chaseRange;
        public GameObject target;

        private Vector3 startPoint;
        private Vector3 currentTarget;
        private float travelTime;
        private UnitHealth unitHealth;
        private float damage;

        public void Init(GameObject target, UnitHealth unitHealth, float damage)
        {
            this.target = target;
            this.unitHealth = unitHealth;
            this.damage = damage;
            startPoint = transform.position;
            currentTarget = target.transform.position;
            InitiateFlight();
        }

        void InitiateFlight()
        {
            float distance = Vector3.Distance(startPoint, currentTarget);
            float maxHeight = Mathf.Max(distance * maxHeightFactor, 0.01f); // Ensure some height
            travelTime = distance / speed;

            StartCoroutine(SimulateProjectile(maxHeight));
        }

        IEnumerator SimulateProjectile(float maxHeight)
        {
            float time = 0;

            // Calculate the vertex of the parabola (the highest point)
            Vector3 vertex = (startPoint + currentTarget) / 2 + Vector3.up * maxHeight;

            bool updatedTarget = false;

            while (time < travelTime)
            {
                time += Time.deltaTime;



                // Calculate the lerp parameter in [0, 1]
                float lerpParameter = time / travelTime;
                float heightParameter = 4 * (-lerpParameter * lerpParameter + lerpParameter);

                Vector3 parabolaPoint = Vector3.Lerp(startPoint, currentTarget, lerpParameter) + Vector3.up * maxHeight * heightParameter;

                // Rotate the arrow to face the next position
                RotateTowardsMovement(parabolaPoint);
                // Move the arrow to the next calculated position
                transform.position = parabolaPoint;

                if (Vector3.Distance(transform.position, currentTarget) < damageRange)
                {
                    unitHealth?.TakeDamage(damage);
                    break;
                }

                yield return null;
            }

            OnReachTarget();
        }


        void RotateTowardsMovement(Vector3 nextPosition)
        {
            Vector3 directionOfMovement = nextPosition - transform.position;
            if (directionOfMovement != Vector3.zero)
            {
                Quaternion rotation = Quaternion.LookRotation(directionOfMovement.normalized);
                transform.rotation = rotation;
            }
        }

        void OnReachTarget()
        {
            Destroy(gameObject);
        }
    }
}