Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function bezier(t: number, ...: Vector2 | Vector3): Vector2 | Vector3
- local points = {...}
- --[ TYPE CHECKING ]--
- local dimension = nil
- for _, v in ipairs(points) do
- local d = typeof(v)
- if d ~= "Vector3" and d ~= "Vector2" then
- error("control points must be Vector2 or Vector3 values")
- end
- if not dimension then
- dimension = d
- elseif d ~= dimension then
- error("cannot mix Vector2 and Vector3 control points")
- end
- end
- --[ CREATE NEXT SET OF POINTS ]--
- local function lerp(v,a,b)
- return v*(b-a)+a
- end
- local pts = {}
- for i = 1, #points-1 do
- local a, b = points[i], points[i+1]
- table.insert(pts, lerp(t, a, b))
- end
- if #pts > 1 then
- return bezier(t, unpack(pts))
- end
- return pts[1]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement