CFrame.fromMatrix, what is it and how can I use it?

The title says it all. What is that? How can I use it for an object rotation. I really have no idea. An example please?


Check out the documentation on this:

vX, vY, and vZ are the directional vectors.

1 Like

In the constructor there’s an argument for ‘lookAt’ of where the front surface should face.
This use of was deprecated for CFrame.fromMatrix() which instead takes 3 vectors of rotation: lookVector, rightVector and upVector.

The documentation gives an example of this useful function.


Is that correct or have I still not understood it???

CFrame.fromMatrix(Vector3 pos,Vector3 vX,Vector3 vY [,Vector3 vZ])
Default for vZ is vX:Cross(vY).Unit

It constructs the CFrame in a similar way to with 12 arguments.


is the same as

In fromMatrix, vX represents rightVector, but in the method it is the 4th, 7th, and 10th arguments. (similar things with upVector and lookVector)

CFrame.fromMatrix is not a combination of and CFrame.Angles (you can still get the same result), it exists for an entirely different reason. (probably for something like the example on the wiki, so the with 12 arguments doesn’t have to be used)


Could you set another example because:

I don’t know now who is telling the truth and who is not telling it. But if you make the,2,3))*CFrame.Angles(math.rad(90), math.rad(90), math.rad(90)) you get the same as CFrame.fromMatrix(,2,3), math.rad(90), math.rad(90), math.rad(90))?

Nope the three arguments are actually unit vectors (like LookVector). LookVector would be vZ, UpVector would be vY, and RightVector would be vX. That means you can do some really weird stuff with conflicting directions, e.g. turning stuff inside out. CFrames represent rotations with these vectors which is why I said its a combination. When you do CFrame.Angles a CFrame is created with its position as all zeros, and three directions (one for each axis).

The reason CFrames can have three directions like this is because mathematically three vectors are used so why not let them be anything.

local Part ="Part", workspace)
Part.CFrame = CFrame.fromMatrix(,10,0), 0,90,0)

This will make a new Part 10 Studs in Y-Axis and turn it 90 deg in Y-Axis?

It needs Vectors instead of numbers.


Ok, but the part was created with 10 Studs in the Y-Axis or?

Is that better???:

Part.CFrame = CFrame.fromMatrix(,10,0),,0,0),,1,0),,0,1))

Yep that’s correct! That will make it face in the Z direction with its top facing the Y direction and the right face in the X direction.

1 Like