Camera Position Lerp With AnimationCurve
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; | |
| 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