How to only lerp CFrame`s angles?

So i have a CFrame and i want to lerp only the angle, the position is not meant to be lerped. I tried doing this:

local x,y,z = CFrame:ToEulerAnglesXYZ()
CFrame.p:Lerp(CFrame.p*CFrame.Angles(x,y,z))

altho the camera just spazzed out it kind of rotated in the place it was supposed to be in but then it teleported to some other rotation, i tried many things. Could anyone help me please?

1 Like

ok so to do this, just separate the angles and the position like so:

local currentAngle = CF1 - CF1.p
local desiredAngle = CF2 - CF2.p
local finalCF = CFrame.new(CF1.p) * currentAngle:Lerp(desiredAngle, 0.5)
2 Likes

Wow i have not actually thought about that, that was so easy thanks man!

1 Like

and how do you lerp only CFrame position?

this is even easier - for a given cframe, you can just lerp its position like any other Vector3, and just add its rotation back at the end:


local goalCFPosition = Vector3.new(4, 8, 5) -- this is the GOAL position you want
local myCF = CFrame.new(1, 2, 1) * CFrame.Angles(0, math.rad(45), 0) -- random cframe

local lerpedPosition = myCF.p:Lerp(goalCFPosition, 0.5)
local finalCF = CFrame.new(lerpedPosition) * (myCF - myCF.p) -- (myCF - myCF.p) is just the rotation CF of the original CFrame
1 Like

@Moonvane i know im late but i just got this problem xD.

can you explain this line
local finalCF = CFrame.new(CF1.p) * currentAngle:Lerp(desiredAngle, 0.5)

I’m kinda new to lerping. from what i learned so far when you lerp. it’ll be something like this.
Part.Cframe = Part.Cframe:Lerp(goal, alpha)

this will lerp the parts current CFrame to the new CFrame.

local finalCF = CFrame.new(CF1.p) * currentAngle:Lerp(desiredAngle, 0.5) <— how does this change the angle without CFrame.Angles and why is it a variable

this is why i need to lerp.
I have a line of code that will change the camera’s lookat direction.

cam.CFrame = CFrame.lookAt(head.Position, head.Position + ToCFrame) * CFrame.Angles(0, math.rad(-90), 0)

ToCFrame is just the normal of the wall. this line will make the camera always face parallel to the detected wall. the problem is if the camera changes angle and is too snappy. so I am trying to lerp the camera orientation so it’s smooth when it changes to a new lookat direction.

so what i did was get the orientation of the CFrame.Lookat

local Goal = CFrame.lookAt(head.Position, head.Position + ToCFrame) * CFrame.Angles(0, math.rad(-90), 0)

local GoalX, GoalY, GoalZ = Goal:ToOrientation()

now i am trying to lerp the camera’s orientation and not the position since lerping the position will slow it down and not make it stick to the player.

it would be better if you can also tell me how i can lerp just the horizontal axis of the orientation as i don’t need the rest to be lerped

I hope you can help. sorry for writing too much i tried to explain my problem to make it clear

1 Like