Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created September 11, 2016 02:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Camera Position Lerp With AnimationCurve
using UnityEngine;
using System.Collections;
public class CameraLerp : MonoBehaviour
{
public float duration = 2;
public AnimationCurve speedCurve = AnimationCurve.EaseInOut(0,0,1,1);
void Start()
{
StartCoroutine(FlyToTarget());
}
IEnumerator FlyToTarget()
{
var startPos = transform.position;
var targetPos = Vector3.one*5;
for (float timer = 0; timer < duration; timer += Time.deltaTime)
{
transform.position = Vector3.Lerp(startPos, targetPos, speedCurve.Evaluate(timer / duration));
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment