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

public class CameraController : MonoBehaviour {

    public GameObject ship;
    Movement ship_movement;
    Vector3 shippos;
    Camera cam;

	// Use this for initialization
	void Start () {
        ship_movement = ship.GetComponent<Movement>();
        cam = GetComponent<Camera>();
	}
	
	// Update is called once per frame
	void Update () {

        shippos = ship.transform.position;
        shippos.z = -10.0f;
        transform.position = shippos;
        cam.orthographicSize = MapToRange(ship_movement.shipRigidbody.velocity.magnitude, 0.0f, 10.0f, 10.0f, 80.0f);
	}


    private float MapToRange(float original, float from1, float to1, float from2, float to2)
    {
        return (original - from1) / (to1 - from1) * (to2 - from2) + from2;
    }
}
