using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Interpol : MonoBehaviour
{
    public float Duration = 0.7f;
    public Vector3 Goal;
    public Transform TransformGoal;
    public bool DestroyOnArrival = false;
    private Vector3 StartPos;
    private float StartTime;
    
    void Start()
    {
        StartPos = transform.position;
        StartTime = Time.time;
    }

    // Update is called once per frame
    void Update()
    {
        float Prog = Mathf.Clamp01((Time.time - StartTime) / Duration);
        Vector3 LocalGoal = Goal;
        if (TransformGoal) LocalGoal += TransformGoal.position;
        transform.position = Vector3.Lerp(StartPos, LocalGoal, Mathf.Pow(Prog,0.3f));
        if(DestroyOnArrival && Time.time > StartTime + Duration)
        {
            GameObject.Destroy(gameObject);
        }
    }
}
