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

public class CameraTarget : MonoBehaviour
{
    public float m_offroadDistanceMin = 3;
    public float m_offroadDistanceMax = 10;

    void Awake()
    {
		
	}
	
	void Update()
    {
        var player = transform.parent;
        Vector3 playerPos = player.position;
        float offroadDistance = playerPos.x;

        float offroadFactor = 0; // -1..0..0..1
        if (offroadDistance < -m_offroadDistanceMin)
            offroadFactor = -(-offroadDistance - m_offroadDistanceMin) / (m_offroadDistanceMax - m_offroadDistanceMin);
        else if (offroadDistance > m_offroadDistanceMin)
            offroadFactor = (offroadDistance - m_offroadDistanceMin) / (m_offroadDistanceMax - m_offroadDistanceMin);
        offroadFactor = Mathf.Clamp(offroadFactor, -1, 1);

        float offroadT = (offroadFactor + 1) / 2;
        float rot = Mathf.Lerp(-90, 90, offroadT);
        Debug.Log(offroadFactor + " " + rot);

    }
}
