Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Created October 28, 2017 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/d0f2a07d7f560e93c93ff487a659d92c to your computer and use it in GitHub Desktop.
Save JonathanYin/d0f2a07d7f560e93c93ff487a659d92c to your computer and use it in GitHub Desktop.
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