Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i only lerp the CFrames rotation?

Asked by 4 years ago

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

0
You can get only rotation without position with `cf - cf.Position` programmerHere 371 — 4y
0
Oh no I've still been using cf.p, I should probably curb that habit. CeramicTile 847 — 4y
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. royaltoe 5144 — 4y

1 answer

Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

0
Brilliant answer and explanation Tymberlejk 143 — 4y
0
thx. royaltoe 5144 — 4y
Ad

Answer this question