Rotation on the World Axis Instead of the Local Axis

I have a position and rotation vector that both can be changed with user input…

local position = Vector3.zero
local rotation = Vector3.zero

…that both are used as components for a part’s CFrame.

-- in some loop
part.CFrame = CFrame.new(position) * CFrame.Angles(
  math.rad(rotation.X),
  math.rad(rotation.Y),
  math.rad(rotation.Z),
)

This is what the part looks like. The local axis are represented as parts, with the Y axis being green, the X axis being red, and the Z axis being blue.

However, with rotation configurations like this (shown below),


Changing rotation.Y rotates around the local Y axis in green…

…instead of the world Y axis in red.

(rotation showed in pink)

How would I change the script to rotate in world space (2) instead of locally (1)?

This reply might be helpful:

TL;DR for what’s going on here:

If you multiple the rotation CFrame THEN the current CFrame, it rotates relative to the world. The problem is that it rotates around the world’s center, the 0,0,0 coordinate, instead of the model’s center! (So a car 50 studs from the center rotated 180 degrees like this would move 100 studs!) The trick is to recenter the CFrame to be rotated at the world’s center (0,0,0), do the world rotation, then move it back to the CFrame’s center.

1 Like

Thank you so much! I’ll get back to you when I implement this

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.