Help With CFrame Rotation

Iam setting model position and rotation using the function PivotTo. The position works fine but the rotation does’nt.

local item = game.Players.Hayden_Almeida.PlayerGui.MainScreen.TelaFull.CharacterScreen.PlayerModel.Frame.ViewportFrame.Char["Origin Cap"] 

item:PivotTo(CFrame.new(-9.3, 5.55, -2) * CFrame.Angles(0,math.rad(90), 0))

In this frist code above you can see i’m setting the angles to 0,90,0 → X,Y,Z respectively and its working. But NOW when i try to set 5º to X using this code:

local item = game.Players.Hayden_Almeida.PlayerGui.MainScreen.TelaFull.CharacterScreen.PlayerModel.Frame.ViewportFrame.Char["Origin Cap"] 

item:PivotTo(CFrame.new(-9.3, 5.55, -2) * CFrame.Angles(math.rad(-5),math.rad(90), 0))

The result is: X=0, Y=90, Z=-5

IMAGE

what i’m doing wrong here?

1 Like

Try switching the order of the Pitch and Yaw rotations like this:

CFrame.Angles(math.rad(90), 0, math.rad(-5))

This will first rotate around the Y-axis by 90 degrees, and then around the Z-axis by -5 degrees. Make sure to adjust other parts of your code accordingly if the order change affects the overall behavior.

You should make an invisible part with the CFrame listed above, so you can simply pivot the model to the part like this:

local item = game.Players.Hayden_Almeida.PlayerGui.MainScreen.TelaFull.CharacterScreen.PlayerModel.Frame.ViewportFrame.Char["Origin Cap"]
local position = workspace.ItemPosition -- the cframe as an invisible part (position and rotation)

item:PivotTo(position.CFrame)
item:PivotTo(CFrame.new(-9.3, 5.55, -2) * CFrame.Angles(math.rad(90),0, math.rad(-5)))

OUTPUT:

X=90, Y=5, Z=0

Didn’t work

Try using CFrame.fromOrientation instead of CFrame.Angles, they are different according to documentation and in game testing.

It worked using fromOrientation than Angles! Thanks man!

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