Created
October 11, 2020 12:23
-
-
Save saturngamesss/1f3ad6ce322b102b962e3f58cfc66656 to your computer and use it in GitHub Desktop.
Smooth Camera Follow for Unity 2D
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
//************** REAL GAMES STUDIO *************** | |
//************************************************ | |
//realgamesss.weebly.com | |
//gamejolt.com/@RealGamesss | |
//realgamesss.newgrounds.com/ | |
//real-games.itch.io/ | |
//youtube.com/channel/UC_Adg-mo-IPg6uLacuQCZCQ | |
//************************************************ | |
using UnityEngine; | |
public class SmoothCameraFollow : MonoBehaviour | |
{ | |
public GameObject player; | |
public float smoothSpeed = 0.125f; | |
public Vector3 offset; | |
void FixedUpdate() | |
{ | |
Vector3 desiredPosition = player.transform.position + offset; | |
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed); | |
transform.position = smoothedPosition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment