Advertisement
ImmersionDr

Code - Third Person Camera in Unity

Mar 5th, 2017
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraController : MonoBehaviour {
  6.  
  7.     public float speed = 1;
  8.     public Transform Target;
  9.     public Camera cam;
  10.    
  11.     // Update is called once per frame
  12.     void LateUpdate () {
  13.         Move ();
  14.     }
  15.  
  16.     public void Move()
  17.     {
  18.         Vector3 direction = (Target.position - cam.transform.position).normalized;
  19.    
  20.         Quaternion lookrotation = Quaternion.LookRotation (direction);
  21.  
  22.         lookrotation.x = transform.rotation.x;
  23.         lookrotation.z = transform.rotation.z;
  24.  
  25.         transform.rotation = Quaternion.Lerp (transform.rotation, lookrotation, Time.deltaTime * 100);
  26.  
  27.         transform.position = Vector3.Lerp (transform.position, Target.position, Time.deltaTime * speed);
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement