using System.Collections; using System.Collections.Generic; using UnityEngine; namespace YKMoon.Math { public class YKBezierHelper { public static Vector3 CubicBezierPos(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) { var i1 = Vector3.Lerp(p0, p1, t); // p1 is the handle for p0 var i2 = Vector3.Lerp(p1, p2, t); // p2 is the handle for p3 var i3 = Vector3.Lerp(p2, p3, t); var j1 = Vector3.Lerp(i1, i2, t); // lerp between the previous 3 points var j2 = Vector3.Lerp(i2, i3, t); var result = Vector3.Lerp(j1, j2, t); // lerp between the 2 for the result return result; } public static Vector3 QuadraticBezierPos(Vector3 p0, Vector3 p1, Vector3 p2, float t) { var i1 = Vector3.Lerp(p0, p1, t); // p1 is the shared handle var i2 = Vector3.Lerp(p1, p2, t); var result = Vector3.Lerp(i1, i2, t); // lerp between the 2 for the result return result; } } }