1.0.1 • Published 9 months ago
@rbxts/ez-bezier v1.0.1
ez-bezier
Cubic bezier curve calculations made simple.
Usage
This example code moves a part up and down a bezier curve.
import { Bezier } from "@rbxts/ez-bezier";
import { Workspace, RunService } from "@rbxts/services";
// optionally change coefficients as last two parameters
const bezier = new Bezier(point0, point1, point2, point3);
const part = new Instance("Part");
part.Anchored = true;
part.Size = Vector3.one;
part.Parent = Workspace;
const speed = 1;
let increasing = false;
let t = 0;
RunService.RenderStepped.Connect(dt => {
t = math.clamp(t + (increasing ? dt : -dt) * speed, 0, 1);
if (increasing && t === 1)
increasing = false;
else if (!increasing && t === 0)
increasing = true;
// 't' is the progress along the curve
part.CFrame = bezier.getCFrame(t);
});