Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i only lerp the CFrames rotation?

I have arms attached to the camera. But i want to lerp the rotation without lerping the position. How can i do that?

3 comments

0

You can get only rotation without position with cf - cf.Position

0

Oh no I've still been using cf.p, I should probably curb that habit.

0

does that explain your question fully or do you need more help? also, camera doesnt have a camera.p, only camera.cframe.p so you're good on that end.

1 answer

✓ Accepted answer

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()

2 comments

0

Brilliant answer and explanation

0

thx.

This discussion is preserved as it was. New answers, comments, and votes are closed.