Loading...

Linear Interpolation Functions | Forum

Save
Save Apr 13 '23

33 Posts

Im going to update this post gradually with lerp and slerp function code as stuff like CFrame.new():lerp and Color3.new():lerp don't exist in clients before 2017.

Color3:

function c3lerp(a, b, t)

   return Color3.new(a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t)

end


CFrame:
function clerp(c1,c2,al)

   local com1 = {c1.X,c1.Y,c1.Z,c1:toEulerAnglesXYZ()}

   local com2 = {c2.X,c2.Y,c2.Z,c2:toEulerAnglesXYZ()}

   for i,v in pairs(com1) do

      com1[i] = v+(com2[i]-v)*a1

   end

   return CFrame.new(com1[1],com1[2],com1[3]) * CFrame.Angles(select(4,unpack(com1)))

end


Please note that the function above is not 100% accurate to modern cframe lerp, consider it as a "legacy" option Here is a newer version that is more accurate (might not work with clients like 2012, havent tested)

Thanks to shrjrd for telling me this


Regular Numbers function lerp(a, b, t)

   return a + (b - a) * t

end

function slerp(a, b, t)

   dot = a.Dot(b)

   if dot > 0.99999 or dot < -0.99999 then

      return t <= 0.5 and a or b

   else       r = math.acos(dot)

      return (a*math.sin((1- t)*r) + b*math.sin(t*r)) / math.sin(r)

   end

end

The Forum post is edited by Save Apr 14 '23
Pringles Moderator
Pringles May 7 '23

57 Posts

dang idek what any of this is
cazum9
cazum9 May 7 '25

91 Posts

thxxxxxxxxx!!!!!!!!!!!!!!!!!!!!!!
cazum9
cazum9 May 7 '25

91 Posts

at the clerp function someone wrote A1 instead of AL
This topic is sticky