I have arms attached to the camera. But i want to lerp the rotation without lerping the position. How can i do that?
the following code lerps PartA
's orientation to match PartB
's orientation:
local PartA = workspace.PartA local PartB = workspace.PartB local start = PartA.CFrame local _end = CFrame.new(PartA.Position) * (PartB.CFrame-PartB.CFrame.p) for i = 0,1,.1 do PartA.CFrame = start:Lerp(_end,i) wait(.1) end
This is the line of code that figures out what PartA with PartB's rotation would be:
local _end = CFrame.new(PartA.Position) * (PartB.CFrame-PartB.CFrame.p)
1) CFrame.new(PartA.Position)
creates a CFrame consisting of only PartA's position and a rotation of (0,0,0).
2) (PartB.CFrame-PartB.CFrame.p)
subtracts the position from PartB's cframe so we are left with a cframe containing only PartB's rotation.
When you multiply CFrame.new(PartA.Position)
and (PartB.CFrame-PartB.CFrame.p)
you're left with a CFrame value containing PartA's position and PartB's rotation.
we can use that as the CFrame value as our 'end' position for the Lerp()