More performant method of tween in loops

Hi guys, i’m working on a flying script and i want it start smooth and if the player stops also end smoothly, the issue is im creating a new tween every heartbeat, it isnt right on timing (written 1 second, takes like 30 seconds) and i heard it can cause memory leaks/ is very laggy.

game:GetService("RunService").Heartbeat:Connect(function(Delta)
	if script.Parent == Character then
			TweenService:Create(BodyVelocity, TweenInfo.new(1), {Velocity = DirectionThing() * 25}):Play()
		
	end
end)

Lerping wouldn’t deliver the same result since its basically ease out

use TweenService:GetValue(), its good for making manual tweens

I tried that i just couldn’t get a good result

you didnt use it properly then

If you want smooth starts and stops, use acceleration and friction

Linear interpolation is ease out? If you meant that you want an ease out effect you can just implement one, there are tons of those on the internet, but still you should just accelerate velocity instead

1 Like

Yes, lerping works like this
+0.5, 0.4, 0.3, 0.2, 0.1, 0.05, 0.02…
It starts fast and ends slow

Using the TweenService for this seems somewhat strange. Why not simply use an incremental value to adjust the speed when a key’s held down?

local SpeedIncrement = 0
local SpeedCap = 50

...
RunService.Heartbeat:Connect(function()
	if (Keys.W - Keys.S) ~= 0 or (Keys.A - Keys.D) ~= 0 then
		SpeedIncrement = math.min(SpeedIncrement + 1, SpeedCap)
	elseif (Keys.W - Keys.S) == 0 and (Keys.A - Keys.D) == 0 then
		SpeedIncrement = math.max(SpeedIncrement - 1, 0)
	end
	...
	BodyVelocity.Velocity = DirectionThing() * (25 * (SpeedIncrement / SpeedCap))
end)
2 Likes

It doesn’t, it’s called “linear” and you’re just using it wrong it’s supposed to have the same change every time unless you’re giving it the wrong alpha

1 Like