Skip to content

Instantly share code, notes, and snippets.

@saturngamesss
Created October 11, 2020 12:23
Show Gist options
  • Save saturngamesss/1f3ad6ce322b102b962e3f58cfc66656 to your computer and use it in GitHub Desktop.
Save saturngamesss/1f3ad6ce322b102b962e3f58cfc66656 to your computer and use it in GitHub Desktop.
Smooth Camera Follow for Unity 2D
//************** 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