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

public class BodyAnimation : MonoBehaviour
{
    public Vector3 lastPosition = new Vector3();

    public float positionalSpeed = 0;

    public float animationFrame = 0;

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

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

        animationFrame += positionalSpeed * 10;

        animationFrame *= 0.95f;

        PlayerController player = PlayerController.Get();

        if (player.transform.localScale.x > 0) {
            transform.rotation = Quaternion.Euler(0, 0, -animationFrame * 4); 
        } else {
            transform.rotation = Quaternion.Euler(0, 0, animationFrame * 4); 
        }
    }
}
