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

public class LightControl : MonoBehaviour {

    public Camera Cam;
    private Quaternion LastRotation;
    private float LastOffset = 0.0f;
    private float BobTimer = 0;
	
	void Start () {
        LastRotation = Cam.transform.rotation;
    }
	
	
	void Update () {

        Quaternion NewRotation = Cam.transform.rotation;

        float OffsetPosition = 0.0f;

        CharacterController Controler = GameManager.Instance.Controler.GetComponent<CharacterController>();
        Vector3 CharacVel = Controler.velocity;
        if (CharacVel.magnitude > 0 && Controler.isGrounded) {
            OffsetPosition = Mathf.Sin(BobTimer * 10.0f);
            //NewRotation *= Quaternion.Euler(0.0f, Mathf.Sin(BobTimer * 10.0f) * 45.0f, 0.0f);
            BobTimer += Time.deltaTime;
        } else {
            BobTimer = 0.0f;
        }

        LastRotation = Quaternion.Lerp(LastRotation, NewRotation, Time.deltaTime * 10.0f);
        LastOffset = Mathf.Lerp(LastOffset, OffsetPosition, Time.deltaTime * 10.0f);

        transform.position = transform.parent.position + transform.parent.right * LastOffset;
        transform.rotation = LastRotation;


    }
}
