How can I lerp infinitely?

Ok, to get to point, I want to make a lerp run infinitely. So would I put it in a repeat until?

Current Code:

local part = game.Workspace.Part1
local part2 = game.Workspace.Part2

for i = 0,1,0.1 do
wait()
part.CFrame = part.CFrame:Lerp(part.CFrame, i)
2 Likes

You can or you could use a while loop

Nope, doesn’t work. It would have to go back and forth, and back and forth. It just reaches the destination and stops.

You should use tween service there.

And then you will have 2 options for it, you can either do this first one which waits for the completion of a tween and then plays another one to wait for it again and repeat.

while true do
     Tween:Play(object, tweenInfo, goal)
     Tween.Completed:Wait()
     GoingBackTween:Play(object, tweenInfo, goal)
     GoingBackTween.Completed:Wait()
end

The second option is for using the last tween info option which is the reversion.

local tweenInfo = TweenInfo.new(the other informations, true) -- The last one is reversion.
while true do
Tween:Play(obj, tweenInfo, goal)
Tween.Completed:Wait()
end
1 Like
for i = 0.1, math.huge, 0.1 do

end

This should do the trick.

1 Like

Perhaps you could do this:

local frequency = 1

local tStart = os.clock()
while true do
    wait()
    local tElapsed = os.clock() - tStart
    local position = math.sin(2 * math.pi * ((frequency * tElapsed) % 1))
    local yourCFrame = point0:Lerp(point1, (position + 1)/2)
end

I’m using os.clock() instead of tick() as Roblox are most likely planning to deprecate tick().

2 Likes

But, I am not trying to use tweenservice. Even though I would know how to use it, I am just trying to use lerps.

That would be bad, TweenServices is what you use for a constant “smooth” change.

But in your case you could simply do this:

while true do
      -- For loop to go forward
      -- For loop to go backward
end

its works, but it doesn’t reverse at all. It just gets to its point and stops.

Would I be able to calculate the first position of the part and place it in the for loop?

Did you ever figure this out? I’m having the same problem.

local part = workspace.Part1
local part2 = workspace.Part2
local movingPart = workspace.movingPart
while true do
     for i = 0, 1, 0.1 do
          task.wait()
          movingPart.CFrame = part.CFrame:Lerp(part.CFrame)
     end
     for i = 0, 1, 0.1 do
          task.wait()
          movingPart.CFrame = part2.CFrame:Lerp(part.CFrame)
     end
end