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

public class imp : MonoBehaviour {

    bool isActive = false;

    public Transform playerTransform;
    public float annoyance = 0.1f;

    public float rotationSpeed = 10f;

    Quaternion newRotation;

    private void Start()
    {
        newRotation = transform.rotation;
    }

    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;
    }
}
