-
-
Save r618/4c360bdb9408bdcc912d99052a61d558 to your computer and use it in GitHub Desktop.
Framerate independent blend
This file contains 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
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