Skip to content

Instantly share code, notes, and snippets.

@pppoe252110
Last active May 16, 2023 04:19
Show Gist options
  • Save pppoe252110/f23d61b825b7d885ca0144fb010eb12a to your computer and use it in GitHub Desktop.
Save pppoe252110/f23d61b825b7d885ca0144fb010eb12a to your computer and use it in GitHub Desktop.
Multiple Lerp(Multilerp) Function Unity C#
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