I don't understand how to rotate stuff in world space

So I have a part with Orientation (0, 0, 90), when I do * CFrame.Angles(0, -math.rad(90), 0) it becomes 90, -90, 0 where I expect it to be (0, -90, 90) (if it doesn’t care about local space). How is that?

1 Like

To rotate by world axis without any local effects, but whilst maintaining the position of the part, you’ll need to extract the Euler angles and simply add the world rotation onto it, then reconstruct a rotational CFrame from those Euler angles, and finally add the position back into it. I use Rx, Ry and Rz to represent the angle you want to turn it through in world space.

local rx, ry, rz = Part.CFrame:ToEulerAnglesYXZ()
Part.CFrame = CFrame:FromEulerAnglesYXZ( rx + Rx, ry + Ry, rz + Rz ) + Part.CFrame.Position

Another option is to rotate a CFrame at the origin by the world rotation you want, then use the * operator to compound the rotation, and then again finally add the position back into it. This has the benefit of fitting neatly into a single line.

Part.CFrame = CFrame.Angles( Rx, Ry, Rz ) * ( Part.CFrame - Part.CFrame.Position ) + Part.CFrame.Position
25 Likes