# CFrame.Angles(x,y, z) Rotation Help

I’m trying to position a knife on the player’s torso. In the command line I’ve written this and for some reason the x and z axis are rotating on the same axis.

``````local knife = workspace.Knife
local torso = workspace.Dummy.UpperTorso

``````

This is what the knife looks like when rotated 45 degrees on the X axis or Z axis.

Two cframes equal same thing:

``````  knife.CFrame = torso.CFrame * CFrame.Angles(math.rad(0), math.rad(90), math.rad(45))
3 Likes

Yes, this is a well known problem. Euler angles (the standard XYZ angles you’re familiar with) have infinite solutions for a given orientation. Usually this results in “Gimbal lock.”

You cannot use XYZ angles in refined cases like this. You must use a matrix or an axis angle.

Rotations [for `.Angles`] are applied in Z, Y, X order.
CFrame

So in the first, you’re rotating about Z by 45 and then about Y by 90.

In the second, you rotate about 90 on Y and then X by 45.

Both of those end up the same.

Solution:

You can explicitly control which one gets multiplied first:

``````-- force rotate on Z before Y (this is the default but we can make it explicit)
Or use `fromOrientation`/`fromEulerAnglesYXZ`, which applies rotations in Y, X, Z order.
``````-- always rotate Y first and then X or Z so these give different answers