Last active
May 16, 2023 04:19
-
-
Save pppoe252110/f23d61b825b7d885ca0144fb010eb12a to your computer and use it in GitHub Desktop.
Multiple Lerp(Multilerp) Function Unity C#
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 static class Multilerp | |
{ | |
public static Vector3 MultilerpFunction(Vector3[] points, float t) | |
{ | |
if (t >= 1) | |
{ | |
return points[points.Length - 1]; | |
} | |
if (t <= 0) | |
{ | |
return points[0]; | |
} | |
int v = Mathf.FloorToInt(t * (points.Length - 1f)); | |
Vector3 from = points[v]; | |
Vector3 to = points[v + 1]; | |
float m = t * (points.Length - 1f) - v; | |
return Vector3.Lerp(from, to, m); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment