Hey, I’m trying to create a cubic-bezier but I’m having some problems with it.
local function cubicBezier(t, p0, p1, p2, p3)
return (1 - t)^3*p0 + 3*(1 - t)^2*t*p1 + 3*(1 - t)*t^2*p2 + t^3*p3
end
for t = 0,1,0.01 do
local TargetPosition = cubicBezier(startpos.p, curve1part.Position, curve2part.Position, endpos);
fireball.Position = TargetPosition;
wait()
end;
I get this error:
[Line 2] - invalid argument #1 (Vector3 expected, got number)
I’m trying to get this part to move along the cubic bezier, according to (TargetPosition) but I keep getting the error. But, how is (t) supposed to be a Vector3 value when it’s the iteration loop value?
local function cubicBezier(t, p0, p1, p2, p3)
return (1 - t)^3*p0 + 3*(1 - t)^2*t*p1 + 3*(1 - t)*t^2*p2 + t^3*p3
end
for t = 0,1,0.01 do
local TargetPosition = cubicBezier(startpos.p, curve1part.Position, curve2part.Position, endpos)
fireball.Position = Vector3.new(TargetPosition)
wait()
end
P.s: Idk how code work but you need use Vector3.new()
I think you forgot to put in the first parameter t which is supposed to be a number value between 0 to 1 which represents a point along the bezier curve from the start position to the end position.
Try this
for t = 0,1,0.01 do
local TargetPosition = cubicBezier(t,startpos.p, curve1part.Position, curve2part.Position, endpos);
fireball.Position = TargetPosition;
wait()
end;