Created
October 28, 2017 22:04
-
-
Save JonathanYin/d0f2a07d7f560e93c93ff487a659d92c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CameraFollow : MonoBehaviour { | |
public Transform target; | |
public float smoothing = 5f; | |
Vector3 offset; | |
void Start() | |
{ | |
offset = transform.position - target.position; | |
} | |
void FixedUpdate() | |
{ | |
Vector3 targetCamPos = target.position + offset; //transform.position is current position, targetCamPos is | |
//the position you want to be at | |
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment