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

public class TailAnimation : MonoBehaviour {
    public enum Type {Small, Big};

    public Type type = Type.Small;

    public float animationFrame = 0;
    public float animationSpeed = 40;

    public Vector3 lastPosition = new Vector3();

    public float positionalSpeed = 0;

    void Start() {
        lastPosition = transform.position;
    }

    void Update() {
        positionalSpeed = Vector2.Distance(lastPosition, transform.position);
	
		lastPosition = transform.position;

        if (positionalSpeed > 0.05f) {
            animationFrame += 1 * animationSpeed;
        } else {
            animationFrame += 0.25f * animationSpeed;
        }
    
        switch(type) {
            case Type.Small:
                transform.rotation = Quaternion.Euler(0, 0, Mathf.Cos(animationFrame) * 7); 
            break;

            case Type.Big:
                transform.rotation = Quaternion.Euler(0, 0, Mathf.Cos(animationFrame * 0.5f) * 3); 
            break;
        }   
    }
}
