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?
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)
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.