CFrame not rotating in correct axis

Hey there. I am attempting to set the CFrame of a Model to a specific CFrame that has an orientation of (-74.474, -90, 0).

To achieve this, I am utilizing CFrame.Angles() to multiply the CFrame of the model by the orientation. However, when I apply this code, the object is rotated -74.474 in the Z axis rather than X axis.

Does anyone have a solution to this?

local model = game.Workspace.Cannon

local pos = CFrame.new(154.749, 150.969, -20.24) * CFrame.Angles(math.rad(-74.474), math.rad(-90), 0)
model:PivotTo(pos)

print(model.PrimaryPart.Orientation)
-- Expected outcome: -74.474, -90, 0 
-- Actual outcome: 0, 90, -74.474

Try this:

local model = game.Workspace.Cannon

local pos = CFrame.new(154.749, 150.969, -20.24) * CFrame.Angles(0, math.rad(-90), 0) * CFrame.Angles(math.rad(-74.474), 0, 0)
model:PivotTo(pos)

print(model.PrimaryPart.Orientation)
-- Expected outcome: -74.474, -90, 0 
-- Actual outcome: 0, 90, -74.474
1 Like

Yeah, somehow that worked.
Is there anything that changes by applying the CFrame rotations in a different order?

Yes, the order in which you apply CFrame rotations affects the final orientation of the model/part.

You can change the order of rotation using a different CFrame constructor:

CFrame.fromEulerAnglesYXZ(math.rad(-74.474), math.rad(-90), 0)

That’s good to know. Thank you :+1:

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