Created
March 3, 2017 11:22
-
-
Save ASPePeX/189068d9aa02e454a58f7c6d6e860fb3 to your computer and use it in GitHub Desktop.
An easy and short script for a smooth 2D follow camera in Unity.
This file contains hidden or 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; | |
public class SmoothCameraFollow2D : MonoBehaviour | |
{ | |
public GameObject Target; | |
public float LerpValue = 0.05f; | |
private float _t; | |
private Vector3 _pos; | |
void Start() | |
{ | |
_pos = this.transform.position; | |
} | |
void FixedUpdate() | |
{ | |
if (Target != null) | |
{ | |
_t = LerpValue; | |
_pos.y = Mathf.Lerp(this.transform.position.y, Target.transform.position.y, _t); | |
_pos.x = Mathf.Lerp(this.transform.position.x, Target.transform.position.x, _t); | |
this.transform.position = _pos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment