Skip to content

Instantly share code, notes, and snippets.

@Amitkapadi
Created March 2, 2023 04:59
Show Gist options
  • Save Amitkapadi/65db195a7d1aa1ec2b7301e78a1d606e to your computer and use it in GitHub Desktop.
Save Amitkapadi/65db195a7d1aa1ec2b7301e78a1d606e to your computer and use it in GitHub Desktop.
[CurveLerpControl] #camera # lerp #animation
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