Created
November 3, 2018 16:24
-
-
Save dyguests/390b03e7c0dff3433731e51107fce805 to your computer and use it in GitHub Desktop.
Unity Camera Smoothly and Fluidly Follow Behaviour
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 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