# How do you rotate a CFrame on the global axis?

What exactly do you mean by that?

1 Like

You can

part.CFrame = part.CFrame:ToWorldSpace(CFrame.Angles(69,420,3.14)*CFrame.Angles(1,33,7))

or

local cframethingies = CFrame.Angles(69,420,3.14)*CFrame.Angles(1,33,7)
part.CFrame = part.CFrame:ToWorldSpace(cframethingies)

right?

Both of those didn’t rotate the part properly.

if not rotated in the expected rotation use math.rad

I used math.rad for it though.

If you meant in the workspace, you can toggle local and global by doing CTRL + L.

Otherwise you just multiply the cframe as an offset to what you’re trying to rotate by

Something like
part.CFrame = CFrame.Angles(0, math.pi, 0) * part.CFrame
part.CFrame = part.CFrame * CFrame.Angles(0, math.pi, 0)

nvm i just tested this, diddd nott work out like i pictured it in my head, has some purpose though.

ok here is what i had in mind:
script.Parent.CFrame = CFrame.Angles(0, rot, 0) * (cf - cf.Position) + cf.Position
where cf is script.Parent.CFrame, this works for my case at least.

4 Likes

You’d want to take the global cframe and convert it to object space, so you’d still be rotating the object locally, but with a cframe that matches the global cframe you want to use (see CFrame:ToObjectSpace() on the wiki). Then you’d just apply the cframe like you would locally.

local part = script.Parent
part.CFrame = part.CFrame:ToObjectSpace(cframethingies)

So like that?

local part = script.Parent
local objectSpaceCF = globalCF:ToObjectSpace(part.CFrame)
part.CFrame = part.CFrame * objectSpaceCF

is how I think you’d implement it

I tried that out, but it didn’t work with all of the axis. How do I make it so it works with each axis?

That way didn’t work. It was orientated really weirdly.

Works for me on each axis, even if the CFrame isn’t cached.

spin.rbxl (18.1 KB)
I messed with it a bit further, feel free to take a look at this. Switching m * step into different parameters works fine for me, assuming that’s the desired effect.

4 Likes

You can only do one parameter at a time though.

Sorry to bump this thread but I’ve seen a few people come looking for a solution to this issue and I’m sure people would like to have a working solution here:

--Change this to the part you're rotating
local Part = workspace.WhateverYourPartIs
local CF = Part.CFrame
--Doesn't have to be stored like this but it helps for clarification
--Change this to the actual angles you're rotating by
local Angles = CFrame.Angles(0,math.pi/2,0)
--Gets the new CFrame in relation to the rotated world Axes
local RotCF = Angles:ToObjectSpace(CF)
--Easier to use fromMatrix here, because it's faster and allows us to use
--the rotational component of the RotCF while preserving position
Part.CFrame = CFrame.fromMatrix(CF.Position,RotCF.XVector,RotCF.YVector,RotCF.ZVector)

Anyways, I hope this works as a solution!

25 Likes

Press Ctrl + L to switch from local to global.

4 Likes

here’s a more intuitive solution I ended up using for the same problem

local cf = part.CFrame
local pos = cf.Position
cf = cf - pos -- get rid of position
cf = CFrame.Angles(0, math.rad(1), 0)) * cf -- rotate the cframe around globally
cf = cf + pos -- add the position back
part.CFrame = cf

simplifiable into this one liner

part.CFrame = (CFrame.Angles(0, math.rad(1), 0) * (part.CFrame - part.Position)) + part.Position
1 Like

This post is a year+ old… I’m sure they’re fine. Just thought I’d point that out.

This devforum thread is the top google search result for this exact question. It is very important for it to be answered.

1 Like

Fair enough.

iuwefghiuwerfwefgwe