function lerp(c1, c2, a) local x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz = c1:components() local cf1 = {x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz} local x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz = c2:components() local cf2 = {x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz} local lerped = {} for i, v in pairs(cf1) do table.insert(lerped, cf1[i] + (cf2[i] - cf1[i]) * a) end return CFrame.new(unpack(lerped)) end function TweenCFrame(object, property, cframe, time) for i = 1, time * 60 do object[property] = lerp(object[property], cframe, i/(time * 60)) rs.RenderStepped:wait() end end while true do TweenCFrame(game.Workspace.Part, "CFrame", CFrame.new(50, 5, 0), 1) TweenCFrame(game.Workspace.Part, "CFrame", CFrame.new(0, 5, 0), 1) end
If you do this it does the lerp but it finishes to soon? When I run the function with a 3 second tween, it finishes in roughly a second. In a second long lerp it finishes in about 1/3rd the time also.
I tested this using Heartbeat instead of RenderStepped, same problem (I did reduce 'time * 60' to 'time * 30'), I also tested with wait() and they both finished too fast. I tested the math but the math seems to be spot on? What's the problem here?
EDIT
The problem was, I am using linear interpolation wrong, updated code