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

public class moveSin : MonoBehaviour
{
    public Transform startMarker;
    public Transform endMarker;

    public float speed = 1.0F;

    private float startTime;

    private float journeyLength;

    bool returnSin = false;

    void Start()
    {
        startTime = Time.time;

        journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
    }

    // Follows the target position like with a spring
    void Update()
    {
        float distCovered = (Time.time - startTime) * speed;

        float fracJourney = distCovered / journeyLength;
        if (transform.position == endMarker.position)
            fracJourney *= -1;

        transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
    }
}

