Skip to content

Instantly share code, notes, and snippets.

@davehampson
Last active January 31, 2023 23:21
Show Gist options
  • Save davehampson/e040ba3cfc826a90c40be8bc9786235c to your computer and use it in GitHub Desktop.
Save davehampson/e040ba3cfc826a90c40be8bc9786235c to your computer and use it in GitHub Desktop.
Framerate independent blend
using UnityEngine;
public class ShipCamera : MonoBehaviour
{
public GameObject m_Ship;
public Vector3 m_RelativePos;
void LateUpdate()
{
//float scale = 0.05f; // Framerate dependent code, bad.
float scale = 1.0f - (float)System.Math.Pow(0.95, Time.deltaTime * 60.0f); // Framerate independent code, good!
Vector3 aim = m_Ship.transform.position + m_RelativePos;
transform.position += (aim - transform.position) * scale;
}
}
@Radicals27
Copy link

Mate, I just HAVE to say - you are a LEGEND!! This solved a days-long issue we were having in our app, so THANK YOU!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment