Created
March 2, 2023 04:59
-
-
Save Amitkapadi/65db195a7d1aa1ec2b7301e78a1d606e to your computer and use it in GitHub Desktop.
[CurveLerpControl] #camera # lerp #animation
This file contains hidden or 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 CurveLerpControl | |
{ | |
public Transform target; | |
public Vector3 focusPoint; | |
public Vector3 pos1, pos2; | |
public Quaternion angle1, angl2; | |
float d1, d2; | |
public void Init() | |
{ | |
d1 = Vector3.Distance(pos1, focusPoint); | |
d2 = Vector3.Distance(pos2, focusPoint); | |
} | |
public void Update(float x) | |
{ | |
var temp = Vector3.Lerp(pos1, pos2, x); | |
float d = Mathf.Lerp(d1, d2, x); | |
var dir = (temp - focusPoint).normalized; | |
target.position = focusPoint + (dir * d); | |
target.rotation = Quaternion.Slerp(angle1, angl2, x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment