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

public class Reticle : MonoBehaviour {

    public AnimationCurve curve;
    public float travelTime;
    Targetable target;
    bool magneting;

    float travelled = 0;

    Vector2 startPosition;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (magneting)
        {
            float percentage = travelled / travelTime;

            transform.position = Vector2.Lerp(startPosition, target.targetTransform.position, curve.Evaluate(percentage));

            travelled += Time.deltaTime;

            if (percentage > 1)
            {
                magneting = false;
            }
        }
        else if (target != null) {
            transform.position = target.targetTransform.position;
        }
        else
        {
            // what even
        }
	}

    public void TravelToTarget(Targetable targetable)
    {
        travelled = 0;
        target = targetable;
        magneting = true;

        startPosition = transform.position;
    }
}
