How can I ensure a part is always rotated in the same direction relative to WorldSpace?

I have a part in workspace. If I run this code:

local part = workspace.Part
part.CFrame = part.CFrame * CFrame.Angles(math.rad(90), 0, 0)

It rotates in the direction that I want. However, if I run this code first:

part.CFrame = part.CFrame * CFrame.Angles(0, 0, math.rad(90))

Running the first segment no longer rotates it in the desired direction. I understand that my original code segment is working just fine, and in reality the axis I want to rotate the part on is “swapped”, but I’m not sure how to get around that. I imagine the solution is to use :ToWorldSpace or :ToObjectSpace, but nothing I’ve tried has worked. Thanks.

The axis of rotation depends on the order in which the CFrames are applied. If the multiplication of angles is after the part CFrame like the example code

Its “relative” to the parts axis and current rotation.

To make it relative to world space do

Part.CFrame = CFrame.Angles() *part.CFrame

This makes it relative to world space as the previous CFrame is CFrame.new

Part.CFrame = CFrame.new()*CFrame.Angles() *part.CFrame

Which is equal to the world axis. However you will also need to fiddle with the positions as well.

This is the second method listed here,

1 Like

Part.CFrame = Part.CFrame.Position * CFrame.Angles()

Never mind, I see the thread’s poster wants to maintain the object’s orientation and rotate it relative to the world space as opposed to rotating the object relative to its object space.