Why multiply CFrame.Angles and not add to CFrame?

I am currently experimenting with welds and weld constraints and trying to add CFrame.Angles with a CFrame and get the following error message:

workspace.Model.Tween.CFrame = workspace.Model.Tween.CFrame + CFrame.Angles(0, math.rad(90), 0):1: invalid argument #2 (Vector3 expected, got CFrame)

I have found that multiplication has exactly the effect I want, but have no idea why this works! Can someone give me a simple explanation?

Fixed code:

workspace.Model.Tween.CFrame = workspace.Model.Tween.CFrame * CFrame.Angles(0, math.rad(90), 0)

It’s because they’re matrices

Read this if you’re smart enough:

When you’re multiplying CFrame with CFrame.Angles, it means you’re changing the part’s rotation.
Remember, CFrame is useful for both rotation and position.

And yes, as @Prototrode said that nicer, they are matrices.

Remember that CFrame also represents position. So it looks like you’re trying to add an angle to a position.[Vector3]

CFrame.new(0,0,0) + CFrame.new(0,5,0) -- error
CFrame.new(0,0,0) + Vector3.new(0,5,0) -- 0, 5, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1  

CFrames are “transformation matrices”, which is a term that comes from linear algebra.

So CFrame.new, CFrame.Angles, etc. all give you a new matrix.

Whoever invented matrices two hundred years ago decided that applying one transformation matrix to another was gonna be called “multiplication,” even though it’s not really like multiplying numbers.

Edit: If there’s one thing I recommend learning for game dev, it’s the basics of linear algebra. This whole series is fantastic: https://youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab

If you only have time to watch one video, chapter 3 is the most important IMO. Go in knowing that CFrames are transformation matrices. The video explains what a transformation matrix is :slight_smile:

1 Like