Tweening an arrow with bezier curve is really laggy

I want to make it less laggy
I spike to around 40-30 fps when it shoots the arrow

	if H:GetAttribute("SpinSpeed") then --spin speed if when projectile is spinning
		local SpinSpeed = H:GetAttribute("SpinSpeed")
		for i=0, 1, .2 do
			local tweenInfo = TweenInfo.new(Speed, Enum.EasingStyle.Linear)
			TW:Create(Projectile, tweenInfo, {CFrame = CFrame.new(Curve.quadraticBezier(i, PointA, PointB, PointC)) * CFrame.Angles((i * 10) * SpinSpeed,0,0)}):Play()
			wait(Speed)
		end
	else
		for i=0, 1, .2 do
			local tweenInfo = TweenInfo.new(Speed, Enum.EasingStyle.Linear)
			TW:Create(Projectile, tweenInfo, {CFrame = CFrame.new(Curve.quadraticBezier(i, PointA, PointB, PointC)) * CFrame.lookAt(Projectile.Position ,Curve.quadraticBezier(i + 0.1, PointA, PointB, PointC)).Rotation}):Play()
			wait(Speed)
		end
	end
local Curve = {}

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

function Curve.quadraticBezier(t, p0, p1, p2)
	local l1 = Curve.lerp(p0, p1, t)
	local l2 = Curve.lerp(p1, p2, t)
	local quad = Curve.lerp(l1, l2, t)
	return quad
end

return Curve

I tried to make it iterate less but it didn’t do anything

Creating so many tweens is definitely not good for performance. They shouldn’t be used at all.

Instead you should bind a function to RenderStep which sets the arrow’s CFrame every frame.

Furthermore, the Curve.quadraticBezier function can be reduced to one mathematical formula, just look it up on the internet.

Lastly, you shouldn’t use a next point on the curve (i + 0.1) as the LookVector since it isn’t that accurate. For this, you should use the first derivative.

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