Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3.  
  4.  
  5. using System.Collections;
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. public class CameraFollow : MonoBehaviour
  14.  
  15. {
  16.  
  17.  
  18.  
  19.     public Transform target;
  20.  
  21.  
  22.  
  23.     public float distance = 3.0f;
  24.  
  25.  
  26.  
  27.     public float height = 3.0f;
  28.  
  29.  
  30.  
  31.     public float damping = 5.0f;
  32.  
  33.  
  34.  
  35.     public bool smoothRotation = true;
  36.  
  37.  
  38.  
  39.     public float rotationDamping = 10.0f;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.     void Update ()
  48.  
  49.     {
  50.  
  51.        
  52.  
  53.         Vector3 wantedPosition = target.TransformPoint (0, height, distance);
  54.  
  55.         Quaternion wantedRotation = Quaternion.LookRotation (-target.forward, Vector3.up);
  56.  
  57.        
  58.  
  59.         transform.position = Vector3.Lerp (transform.position, wantedPosition, damping * Time.deltaTime);
  60.  
  61.         transform.rotation = Quaternion.Lerp (transform.rotation, wantedRotation, damping * Time.deltaTime);
  62.  
  63.        
  64.  
  65.     }
  66.  
  67.    
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement