Advertisement
MysteryGM

Unity_SimpleFollowCamera

Aug 30th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SimpleFollowCamera : MonoBehaviour
  6. {
  7.     public GameObject Target;
  8.     public float CameraSpeed = 4f;
  9.  
  10.     Vector3 Startoffset = Vector3.zero;
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         Startoffset = this.transform.position - Target.transform.position;
  15.     }
  16.  
  17.     // FixedUpdate is called 50 times per second
  18.     void FixedUpdate()
  19.     {
  20.         Vector3 CameraPinnedPos = Target.transform.position + Startoffset;
  21.         this.transform.position = Vector3.Slerp(this.transform.position, CameraPinnedPos,Time.deltaTime * CameraSpeed);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement