Skip to content

Instantly share code, notes, and snippets.

@thebne
Created January 14, 2021 09:51
Show Gist options
  • Save thebne/92f8df3273df39f9b8b8f61e9e049188 to your computer and use it in GitHub Desktop.
Save thebne/92f8df3273df39f9b8b8f61e9e049188 to your computer and use it in GitHub Desktop.
Unity Bezier 5 points
void DrawBezierCurve(Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3, Vector3 point4)
{
lineRenderer.positionCount = 50;
float t = 0f;
Vector3 B;
for (int i = 0; i < lineRenderer.positionCount; i++)
{
B = 1 * (1 - t) * (1 - t) * (1 - t) * (1 - t) * point0
+ 4 * (1 - t) * (1 - t) * (1 - t) * t * point1
+ 6 * (1 - t) * (1 - t) * t * t * point2
+ 4 * (1 - t) * t * t * t * point3
+ 1 * t * t * t * t * point4
;
lineRenderer.SetPosition(i, B);
t += (1 / (float)lineRenderer.positionCount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment