// based on http://answers.unity3d.com/questions/29183/2d-camera-smooth-follow.html
using UnityEngine;
using System.Collections;

public class SmoothCamera : MonoBehaviour {
    public float dampTime = 0.15f;
    public float vCorrect = 0.75f;
    private Vector3 velocity = Vector3.zero;
    public Transform target;

    void Update() {
        if (target) {
            Vector3 point = GetComponent<Camera>().WorldToViewportPoint(target.position);
            Vector3 delta = target.position - GetComponent<Camera>().ViewportToWorldPoint(new Vector3(0.5f, vCorrect, point.z));
            Vector3 destination = transform.position + delta;
            transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
        }
    }
}