How to use :Lerp() to make a part move at a constant speed to a coordinate?

Lets say I have a part… and now I want to use :Lerp(CFrame, 0.01) to move it to CFrame.new(25, 0, 25). When I do that… this happens:

As you can see, the farther away the part is from the coordinates it wants to get lerped to, the faster it goes to it’s destination, but the closer it is to the coordinates, it is slower. Is there any way I can make this move at a constant, and smooth speed using :Lerp()?

Here is the code I am using:

function lookAt(target, eye)
    local forwardVector = (eye - target).Unit
    local upVector = Vector3.new(0, 1, 0)
    -- You have to remember the right hand rule or google search to get this right
    local rightVector = forwardVector:Cross(upVector)
    local upVector2 = rightVector:Cross(forwardVector)
 
    return CFrame.fromMatrix(eye, rightVector, upVector2)
end 

game:GetService("RunService").Stepped:Connect(function()
	workspace.Part.CFrame = workspace.Part.CFrame:Lerp(CFrame.new(25, 0, 25), .01)
	game.Workspace.Part.CFrame = lookAt(Vector3.new(0, 0, 0), workspace.Part.Position)
end)

This should work:

local initial = workspace.Part.CFrame
local target = CFrame.new(25, 0, 25)
local TIME = 5

local s = tick()
game:GetService("RunService").Stepped:Connect(function()
    workspace.Part.CFrame = initial:lerp(target, math.min((tick() - s) / TIME, 1))
end)
8 Likes