Help With CFrame Angles

I am slightly confused about the CFrame.Angles constructor. Is CFrame.Angles(x, y, z) the same thing as CFrame.Angles(x, 0, 0) * CFrame.Angles(0, y, 0) * CFrame.Angles(0, 0, z)? From what I know and have, it should be the same thing because the multiplication operator offsets one CFrame from another CFrame. However, from what I tested so far, the X-component, for some reason, adds up with the Z-component, so it isn’t the same thing.

Let me clarify myself. This following line just rotates the CFrame of the block by 90 degrees.

-- part is the green part, and root is the spaceship on the bottom
part.CFrame = root.CFrame * CFrame.Angles(0, math.pi / 2, 0) *
	CFrame.new(0, 10, 0)

image

Now, if I change the X-component to 30 degrees, It weirdly offsets Z-orientation.

part.CFrame = root.CFrame * CFrame.Angles(math.pi / 6, math.pi / 2, 0) *
	CFrame.new(0, 10, 0)

image

Now if I do add a Z-orientation of -30 degrees, the 30 degrees from the X-orientation adds up with -30 degrees from the Z-orientation to cancel each other out.

part.CFrame=root.CFrame * CFrame.Angles(math.pi/6, math.pi/2, -math.pi/6)*
	CFrame.new(0, 10, 0)


Well, Z-orientation is 0.
image

But multiplying CFrames created using CFrame.Angles gives me more of what I was looking for.

part.CFrame = root.CFrame * CFrame.Angles(0, math.pi / 2, 0) *
	CFrame.Angles(math.pi / 6, 0, 0) * CFrame.new(0, 10, 0)

Can someone can explain to me what the CFrame.Angles(x, y, z) really does, and why the X only changes Z? No matter how hard I try, I can’t seem to offset X- and Y-orientation with a single CFrame.Angles() because Z gets offset instead of X. I have already tried changing Z only, but that changes Z, not X.

1 Like

I’m not really sure what’s going on. What is the root.CFrame? This is the only thing that I can see that could cause issues.

CFrame.Angles(x,y,z) is indeed the same as multiplying them together individually. I made two parts spin on the z and x axes, one using multiplication and the other using CFrame.Angles(x,y,z) to prove it.

2 Likes

Yes, I see that the parts spin identically. Root is the spaceship as I mentioned before. I should also note that the X and Z glitch only occurs when I multiply it to another CFrame like root.CFrame. Otherwise, it seems to work intuitively, the individual angle components are multiplied together.

This is because CFrame multiplications are not commutative which means you will get different results depending on what order you multiply your angles in as CFrame.Angles work by rotating a CFrame around the 3 axis in a specific order.
You can also test this in real life if you use the 3-finger rule to rotate your hand by using your thumb, index and middle finger as an X-/Y-/Z-Axis, your hand will end up in different positions depending on what order you rotate your hand in.
CFrame.Angles rotate the CFrame in the X-Y-Z order.
That`s why this will print true:

print(CFrame.Angles(1,0,0)*CFrame.Angles(0,1,0)*CFrame.Angles(0,0,1) == CFrame.Angles(1,1,1)) 

Whereas these will print false:

print(CFrame.Angles(1,0,0)*CFrame.Angles(0,1,0) == CFrame.Angles(0,1,0)*CFrame.Angles(1,0,0))

This is why you get different results with your code as you changed the order in which you rotate your CFrame, you rotated the CFrame at the Y-Axis first and then at the X-Axis:

part.CFrame = root.CFrame * CFrame.Angles(0, math.pi / 2, 0) *
	CFrame.Angles(math.pi / 6, 0, 0) * CFrame.new(0, 10, 0)

Simply swaping both CFrame.Angles should fix your issue.

3 Likes

I see the problem. CFrame multiplication isn’t commutative. When multiplying angles, the angle gets offset in respect to the word axes, rather than the object axes. By doing CFrame.Angles(math.pi/6, math.pi/2, -math.pi/6), the part rotates 30 degrees on the X. Then, the part is rotated 90 degrees, but during this stage, the X-axis of the part aligns with the Z-axis. So whatever X-rotation was done turns into Z-rotation. Lastly, Z-rotation is added.

1 Like

Saved my life bro thanks.I was struggling