Eriknem

shooter2

Nov 6th, 2016
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraFollow : MonoBehaviour
  5. {
  6.     public Transform target;            // The position that that camera will be following.
  7.     public float smoothing = 5f;        // The speed with which the camera will be following.
  8.  
  9.     Vector3 offset;                     // The initial offset from the target.
  10.  
  11.     void Start ()
  12.     {
  13.         // Calculate the initial offset.
  14.         offset = transform.position - target.position;
  15.     }
  16.  
  17.     void FixedUpdate ()
  18.     {
  19.         // Create a postion the camera is aiming for based on the offset from the target.
  20.         Vector3 targetCamPos = target.position + offset;
  21.  
  22.         // Smoothly interpolate between the camera's current position and it's target position.
  23.         transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
  24.     }
  25. }
Add Comment
Please, Sign In to add comment