Part Does not rotate along X axis

I was creating an animation and I wanted to change the rotation of my object. However, when I want to set the X Rotation value of my object to 20, the Z value becomes 20. Likewise, when I want to set the Z value to 20, the Z value is 20 again. Also, if I set both X and Z values to 20, this time the Z value becomes 40. I don’t understand why, can you help me?

local Tween = TweenService:Create(Chest, Tweeninfo3, {CFrame = CFrame.Angles(math.rad(20),math.rad(90),0)})

Rotation can sometimes go in ZYX and XYZ. Idk why

But isn’t it strange that the value I give to x is added to z?

I think it’s a different form of Euler angles. Found I Wikipedia page on it

1 Like

You’ve Try To Play The Tween ?

I couldn’t fully explain it to you, but I have two suggestions.
You could multiplying the postion CFrame by your angle CFrame, or what I think may be the easiest solution, tween Orientation instead of CFrame.
Let me know if this works!

The Orientation property of the part has a different rotation order than CFrame.Angles. Rotations are intrinsic, meaning the rotations are applied on a per-axis basis about the current rotation of the CFrame’s axes. CFrame.Angles applies rotations on each axis in the order X → Y → Z, while the Orientation property reflects its rotation on each axis as if it were applied in the order Y → X → Z

Using the XYZ rotation order, here is how intrinsic rotations are applied to an identity CFrame (CFrame with zero’d position and default orientation) when you want to rotate on the X axis by 15 degrees, Y by 30 and Z by 60:

  • Rotate on the global (world’s) X axis by 15 degrees. This will change the direction of the Y and Z axes
  • Rotate on the new Y axis from the previous rotation by 30 degrees. This will change the direction of the X and Z axes
  • Rotate on the new Z axis from the previous rotation by 60 degrees

You would better understand how rotations are applied using different rotation orders by trying it out yourself - This documentation page outlines how you can visualize the many rotation orders with the 1st snippet of code. When you try the XYZ and YXZ orders, the results are different - so it makes sense as to why the Orientation property and the values you supplied for the rotation are different. Since applying rotations with different rotation orders yields different results, representing the same orientation using the two different rotation orders are different

You can apply rotations using the same rotation as the Orientation property by using CFrame.fromEulerAnglesYXZ / CFrame.fromOrientation / CFrame.fromEulerAngles(rx, ry, rx, Enum.RotationOrder.YXZ)

1 Like

yes of course i tried. RandomRandom

It seems like you are encountering a common confusion related to Euler angles in Roblox. When using CFrame.Angles, the order of the rotations matters, and it’s important to understand that each rotation affects subsequent rotations.

In your script, you are creating a CFrame with the following angles:

CFrame.Angles(math.rad(20), math.rad(90), 0)

This means you’re applying a rotation of 20 degrees around the X-axis first, then a rotation of 90 degrees around the Y-axis, and finally, a rotation of 0 degrees around the Z-axis.

If you are experiencing unexpected behavior, it might be due to how the rotations are being combined. To ensure that the rotations are applied in the order you expect, you can use the * operator to combine them explicitly:

local chestRotation = CFrame.Angles(math.rad(20), 0, 0) * CFrame.Angles(0, math.rad(90), 0)
local Tween = TweenService:Create(Chest, Tweeninfo3, {CFrame = chestRotation})

This way, the rotation around the X-axis is applied first, and then the rotation around the Y-axis. Adjust the order based on your desired rotation sequence, I hope this helps.

I wrote the code as follows, but when I check it in the “properties” section, the Z value is 45.

local Tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local Chest = ReplicatedStorage.Chest.Chest1.MeshPart:Clone()
Chest.Parent = player.PlayerGui.ScreenGui.ViewportFrame

print(Chest.Rotation) -- 0,90,0
local chestRotation = CFrame.Angles(math.rad(45), 0, 0) * CFrame.Angles(0, math.rad(90), 0)
local Tween = TweenService:Create(Chest, Tweeninfo, {CFrame = chestRotation})
Tween:Play()

Tween.Completed:Connect(function()
   print(Chest.Rotation) -- 45,90,0
end)
1 Like

If I set the Z value to 45 it gives this output.

90, 31.690000534057617, 90

local chestRotation = CFrame.Angles(0, 0, math.rad(45)) * CFrame.Angles(0, math.rad(90), 0)
1 Like

When you set the Z value to 45 degrees using CFrame.Angles(0, 0, math.rad(45)) , it’s important to note that this rotation is applied around the Z-axis. However, in Roblox, the default orientation of parts in 3D space has the Z-axis pointing upwards. Therefore, when you apply a rotation around the Z-axis, it affects the local X and Y axes.
In your case, it looks like you are creating a rotation around the Z-axis first, and then applying a rotation around the Y-axis. This can lead to unexpected results because the rotations are being combined in a way that may not align with your expectations.
If you want to set the Z value to 45 degrees while keeping the orientation more intuitive, you should adjust the order of rotations. For example:

 local chestRotation = CFrame.Angles(0, math.rad(90), 0) * CFrame.Angles(0, 0, math.rad(45))

whole modified script

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer

local Tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local Chest = ReplicatedStorage.Chest.Chest1.MeshPart:Clone()
Chest.Parent = player.PlayerGui.ScreenGui.ViewportFrame

local chestRotation = CFrame.Angles(0, math.rad(90), 0) * CFrame.Angles(0, 0, math.rad(45))
local Tween = TweenService:Create(Chest, Tweeninfo, {CFrame = chestRotation})
Tween:Play()

RunService.Heartbeat:Connect(function()
    print(Chest.Rotation)
end)

Tween.Completed:Connect(function()
   print(Chest.Rotation) -- 45,90,0
   RunService:Disconnect() -- Disconnect the heartbeat connection when the tween is complete
end)

This way, you first rotate around the Y-axis and then around the local Z-axis. Adjust the order based on your desired sequence of rotations.

2 Likes

Thank you for your message, it solved this problem, I can’t thank you enough.

No problem, don’t forget to mark this topic solved.

1 Like

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