How to calculate lerp with speed and time to complete it?

Hi, i’m trying to make calculation for lerping part, i give speed in studs per second, and a wait time is 1/60

local function Lerp(a,b,t)
	return a+(b-a)*t
end
folder.Change.Changed:Connect(function()
	local distance = (Finish-Start).Magnitude
	
	local Time = distance/Speed
	local startTime = tick()
	

	for i = 0,1,factor do
		
		
		local step = (Time*i)/Time
		
		
	    Brick.Position = Lerp(Start,Finish,step) 
		task.wait(0)
	end
local endTime = tick()-startTime

print(endTime,Time)

problem is i don’t know how to calculate on how much i should move or wait the lerp, please help me with that

1 Like

this is how to do lerping

local part = workspace.Part

local lerp_time = 1

local start_position = part.Position
local end_position = Vector3.new(0,10,0)

local lerping
local alpha = 0

task.wait(5)

lerping = game["Run Service"].Heartbeat:Connect(function(delta)
	alpha += delta/lerp_time
	part.Position = start_position:Lerp(end_position,math.min(1,alpha))
	if alpha >= 1 then
		lerping:Disconnect()
	end
end)
2 Likes

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