Bezier Curve Help

Hello, i am RequiemZap , i was working on bezier curve for my effect,
i had an issue

  • First Issue that i wanted to set a speed for bezier curve (when i aim my mouse far away its speed becomes twice as fast as light speed)

  • Second Issue when i was trying to fix the speed thing, the code doesn’t work anymore, and prints help

function lerp(a, b, t)
	return a + (b - a) * t
end

function quadraticBezier(t, p0, p1, p2)

	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)

	return quad
end

function VenomModule.VenomSpit(Character,MoveData,MousePos)
	local Effect = game.ReplicatedStorage.Part:Clone()
	Effect.CFrame = Character.Head.CFrame * CFrame.new(0,0,-3)
	Effect.Parent = workspace.Effects

	local Middle = Effect.Position:Lerp(Character.Head.Position + Vector3.new(25,5,0),.5)
	local speed = 100 
	for i = 0, 1, (MousePos - Effect.Position).Magnitude / speed do
		Effect.CFrame = CFrame.new(quadraticBezier(i, Effect.Position, Middle, MousePos))
		print('Help')
		task.wait()
	end

end

i think my issue is with (MousePos - Effect.Position).Magnitude / speed Part

nvm fixed it by myself

for anyone wondering how i did it etc
here is the code, i might stop using bezier curves later one

function lerp(a, b, t)
	return a + (b - a) * t
end

function quadraticBezier(t, p0, p1, p2)

	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)

	return quad
end

function VenomModule.VenomSpit(Character,MoveData,MousePos)
	local Effect = game.ReplicatedStorage.Part:Clone()
	Effect.CFrame = Character.Head.CFrame * CFrame.new(0,0,-3)
	Effect.Parent = workspace.Effects

	local Middle = Effect.Position:Lerp(Character.Head.Position + Vector3.new(25,5,0),.5)
	local Distance =(MousePos - Effect.Position).Magnitude 
	local speed = 100

	local Time =  Distance/speed

	for i = 0, 1, .1 do
		Effect.CFrame = CFrame.new(quadraticBezier(i, Effect.Position, Middle, MousePos))
		print('Help')
		task.wait(Time)
	end

end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.