Multiplying CFrames?

I’ve been scripting for a while now, and I’ve gotten used to multiplying CFrames in order to accomplish something. The way I’ve always seen it, is adding with Vector3 values.

Let’s say I wanted to move an object 5 studs forward:

Part.Position = Part.Position + Vector3.new(5,0,0)

As you can see, in the example, we are moving the part forward on the X axis, by adding a Vector3 value.

Now with CFrame it would look like this:

Part.CFrame = Part.CFrame.lookVector*100

I’m trying to figure out why CFrames are multiplied mostly, and why Vector3 is added.

So what happens is that you could say that the Vector3 is like { 5, 0, 0 } like a table so what happens is the position is also like that example { 10, 0, 0 } so what it does is that it says { 5 + 10, 0 + 0, 0 + 0} = { 15, 0, 0 } the same is true with CFrame so instead of adding it will multiply the values

The reason why is cause you are basically doing 1*100 where 1 represents the direction. If you want to add cframes like vector3s we need to pretty much ignore everything else in it. That is why we just use vector3. However you can break up the cframes components and i forgot what they are in the api but its like c0, c1 and c2

We multiply CFrames because they are meant to represent a 4x4 transformation matrix, made up of a 3x3 rotation submatrix, 1x3 position, with an extra 1x4 to keep the matrix square. In this sense, adding CFrames rather than multiplying them would result in a matrix with a non-orthogonal rotation and an improperly translated position. More on this here.

2 Likes

This is quite complicated to understand, and I believe I need at least a 10th grade mathematics understanding to get this. However, I will use your explanaiton in the future to futher understand the math behind all of this. Thanks!

You’d usually take a linear algebra class in university to cover this