Advertisement
JuiceBoxx

Smooth Camera Script

Mar 16th, 2015
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1.      using UnityEngine;
  2.     using System.Collections;
  3.     public class SmoothCamera2D : MonoBehaviour {
  4.     public float dampTime = 0.15f;
  5.     private Vector3 velocity = Vector3.zero;
  6.     public Transform target;
  7.     // Update is called once per frame
  8.     void Update ()
  9.     {
  10.     if (target)
  11.     {
  12.     Vector3 point = camera.WorldToViewportPoint(target.position);
  13.     Vector3 delta = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
  14.     Vector3 destination = transform.position + delta;
  15.     transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
  16.     }
  17.     }
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement