My suggestion for this would simply be an addition to the * operator for CFrames which allow us to multiply a CFrame by a number.
CFrame*Number
For example
MyCFrame*0.5 would be half interpolated between CFrame.new() and MyCFrame
How we could make an interpolate function from this is:
local function Interpolate(CFrame0,CFrame1,t)
local RelativeCFrame=CFrame0:inverse()*CFrame1--The CFrame such that CFrame0*RelativeCFrame=CFrame1
local InterpolatedRelativeCFrame=RelativeCFrame*t--Using the operation I'm suggesting
return CFrame0*InterpolatedRelativeCFrame
end
Here’s about what would go on in the background.
--Handles all errors correctly.
local cf, v3 = CFrame.new, Vector3.new
local components = cf().components
local acos, cos, sin = math.acos, math.cos, math.sin
local function CFrameTimesNumber(c,n)
local x, y, z, xx, yx, zx, xy, yy, zy, xz, yz, zz = components(c)
local xxyyzz = xx + yy + zz
if zz > 0.1^8-1 and xxyyzz < 3-0.1^8 then
local t = acos((xxyyzz - 1) / 2)*n
local c, s = cos(t), sin(t)
local ax, ay, az = yz - zy, zx - xz, xy - yx
local m = (ax*ax + ay*ay + az*az) ^ 0.5
local nax, nay, naz = ax/m, ay/m, az/m -- Normalized axis
return cf(x*n, y*n, z*n, --Position
t*nax*nax + c, t*nax*nay - naz*s, t*nax*naz + nay*s,
t*nax*nay + naz*s, t*nay*nay + c, t*nay*naz - nax*s, --Matrix
t*nax*naz - nay*s, t*nay*naz + nax*s, t*naz*naz + c)
elseif n > 0.5 then
local nn = 1 - n
return c - v3(x*nn, y*nn, z*nn)
else
return cf(x*n, y*n, z*n)
end
end