Vector3 expected, got number - cubic-bezier

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?

Omg… You trying to summon demon?(You need use Vector3.new(number’s here))

yeah, but argument #1 is (t), and t is the number being used in the loop, right? So surely it can’t be a vector3 value?

Yea? Try this:

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()

Same error, the error I get (Vector3 expected, got number) is for this line:

return (1 - t)^3*p0 + 3*(1 - t)^2*t*p1 + 3*(1 - t)*t^2*p2 + t^3*p3

not the one in the for loop.

try setting the fireballs CFrame instead of position as it is what it looks like you are trying to do. Like this:

fireball.CFrame = CFrame.new(TargetPosition)

Same error, Vector3 expected, got number

return (1 - t)^3*p0 + 3*(1 - t)^2*t*p1 + 3*(1 - t)*t^2*p2 + t^3*p3

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;
1 Like

Yep, that was it. Thanks again dthecoolest!
I should have seen this mistake earlier

1 Like