Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created September 11, 2016 02:51
Show Gist options
  • Select an option

  • Save unitycoder/eb3833e1bda8ac2c04fca2a3eb343cb0 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/eb3833e1bda8ac2c04fca2a3eb343cb0 to your computer and use it in GitHub Desktop.
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