Skip to content

Instantly share code, notes, and snippets.

@r618
Forked from davehampson/ShipCamera.cs
Created September 29, 2018 10:37
Show Gist options
  • Save r618/4c360bdb9408bdcc912d99052a61d558 to your computer and use it in GitHub Desktop.
Save r618/4c360bdb9408bdcc912d99052a61d558 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment