I was wondering if there was a way to make a part move to another part within a certain time frame. I originally used the function below for this purpose. However, this function relies on speed and not a specific time. Is there a way to make this function work based on a specific time?
function Lerp(Obj: any, Goal: CFrame, Speed: number, BreakOnComplete: boolean)
while true do
local deltaTime = task.wait()
local distance = (Obj.Position - Goal.Position).Magnitude
local speed = Speed * deltaTime -- distance traveled between elapsed time
local estimatedTime = speed / distance -- obtain a lerp fraction between distance traveled in a frame divided by the overall distance towards the goal
local adjustedLerpAlpha = math.min(estimatedTime, 1) -- prevent the lerp from going over 1 which is over the lerp goal
Obj.CFrame = Obj.CFrame:Lerp(Goal, adjustedLerpAlpha) -- lerps the position values at constant speed
if BreakOnComplete == true and Obj.CFrame == Goal then
print("Complete!")
break
end
end
end
If I need to explain this better, do let me know.