Skip to content

Instantly share code, notes, and snippets.

@dyguests
Created November 3, 2018 16:24
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 dyguests/390b03e7c0dff3433731e51107fce805 to your computer and use it in GitHub Desktop.
Save dyguests/390b03e7c0dff3433731e51107fce805 to your computer and use it in GitHub Desktop.
Unity Camera Smoothly and Fluidly Follow Behaviour
using UnityEngine;
using System.Collections;
public class Follow : MonoBehaviour {
public GameObject objectToFollow;
public float speed = 2.0f;
void Update () {
float interpolation = speed * Time.deltaTime;
Vector3 position = this.transform.position;
position.y = Mathf.Lerp(this.transform.position.y, objectToFollow.transform.position.y, interpolation);
position.x = Mathf.Lerp(this.transform.position.x, objectToFollow.transform.position.x, interpolation);
this.transform.position = position;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment