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

public class imp : MonoBehaviour {

    bool isActive = false;

    private Transform playerTransform;
    public float annoyance = -10.0f;

    public float rotationSpeed = 100f;

    Quaternion newRotation;

    private void Start()
    {
        newRotation = transform.rotation;
        playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
    }

    void FixedUpdate () {
        if (isActive)
        {
            float rotZ = (playerTransform.position.z - transform.position.z) * annoyance;
            float rotX = (playerTransform.position.x - transform.position.x) * -annoyance;

            newRotation = Quaternion.Euler(rotZ, 0.0f, rotX);
            //transform.rotation = newRotation;
        }
        var step = rotationSpeed * Time.deltaTime;

        transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, step);
    }

    private void OnCollisionEnter(Collision collision)
    {
        isActive = true;
    }
}
