using UnityEngine;
using System.Collections;

public class Splatter : MonoBehaviour 
{
    public float Height;
    public float Floor;
    public float XVel;
    public float UpTime = 0.5f;
    private float startTime;
    private Vector3 startPos;

	void Start () 
    {
        startPos = transform.position;
        startTime = Time.time;

        Floor = transform.position.y - 0.15f;
        Height = Random.Range(0.05f, 0.25f);
        XVel = Random.Range(-0.45f, 0.45f);
        transform.localScale *= Random.Range(1.0f - Mathf.Abs(XVel), 1.4f);
	}
	
	void Update () 
    {
        if(transform.position.y < Floor)
        {
            GameObject.Destroy(gameObject);
            return;
        }

        float timeSpent = (Time.time - startTime);
        float progressFactor = timeSpent / UpTime;

        Vector3 vert = new Vector3(0, Height * (-Mathf.Pow(2 * progressFactor - 1, 2) + 1), 0);
        transform.position = startPos + vert + XVel * timeSpent * new Vector3(1, 0, 0);
	}
}
