How to only apply a rotation on a CFrame?

Hello devs! Quick question? How do you only apply a rotation on a CFrame value? I’m trying to tween my camera so that it has a guns recoil effect and the tween is also affecting the Cframe’s position of the camera (which I expected). I looked around a bit but didn’t come to a conclusion. Anybody know how to only update the rotation of a CFrame without updating its position?

Thanks in advance!
Edit: Clarification made here

local c = workspace.Camera
c.CFrame *= CFrame.Angles(math.rad(5),0,0)

To clear myself up, I meant to ask if anybody knows how to only update the rotation of a CFrame without updating its position?

That’s what that does, because he used *= instead of =.

the code does that

charrrrrrr

my bad, I overlooked that

(to short of a message)

You can use this.

local pos = --yourpos
local newcframe = CFrame.new(pos) * Crame.Angles(math.rad(x),math.rad(y),math.rad(z))

It creates a new CFrame with the current position and just changing the orientation.

2 Likes

So after a bit more digging around i found this post

which basicly concludes my first idea of using lerping to achive the goal I want, but this seemed… just a bit unreasonable

Now the goal I want is what this guys question was, which basic asks if you can tween the rotational cframe value of the camera but still allow its position to update with the player. and as previously stated, it seems a bit unreasonable because you can tween the orientation of a part, and still move it around, but you can’t tween the rotation and move it around. Infact you cant even set a rotation seperately from the position, without the position defaulting to 0,0,0

I never did understand why if you wanted wanted to update the rotation of a parts cframe, you had to do this (below), considering you can manipulate the vector3’s orientation and position seperately

part.CFrame = Part.CFrame * CFrame.Angles(1,1,1)
--or
part.CFrame = CFrame.new(CFrame.X, CFrame.Y, CFrame.Z) * CFrame.Angles(1,1,1)

-- but why not
Part.CFrame.Rotation = CFrame.Angles(1,1,1)

anybody know why CFrames are the way they are?

At a basic level, CFrames store both position and rotation. If you set a CFrame, you overwrite the old one.

The reason this is is a little more complicated. In a nutshell, this allows for some extremely useful mathematical operations (performed behind the scenes) such as moving and rotating parts relative to each other.

The reason for that is entirely too complicated, but to give you some keywords in case you want to Google it, this is what you need to know. CFrames are a 4x4 matrix and all operations on CFrames are performed using the branch of mathematics called “linear algebra.” This encompasses the reason we use multiplication instead of addition to add them together, how to subtract them and get relative positioning, rotate CFrames around an axis, etc. But it’s a college level math subject, with a few semesters of prerequisites.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.