Skip to content

Instantly share code, notes, and snippets.

@NotStonee
Created June 22, 2023 22:47
Show Gist options
  • Save NotStonee/209c878c2f748cac9dce5e09acea9ab1 to your computer and use it in GitHub Desktop.
Save NotStonee/209c878c2f748cac9dce5e09acea9ab1 to your computer and use it in GitHub Desktop.
unity camera follow script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraFollow : MonoBehaviour
{
public float FollowSpeed = 2f;
public float yOffset =1f;
public Transform target;
// Update is called once per frame
void FixedUpdate()
{
Vector3 newPos = new Vector3(target.position.x,target.position.y + yOffset,-10f);
transform.position = Vector3.Slerp(transform.position,newPos,FollowSpeed*Time.deltaTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment