CFrame.Angles is broken

Current code:

local players: Players = game:GetService("Players")

local function onPlayerAdded(player: Player)
	local function onCharacterAdded(character: Model)
		local torso: BasePart = character:WaitForChild("Torso") :: BasePart
		
		local sledgehammer: Model = script.Sledgehammer:Clone()
		local sledgehammerPrimaryPart: BasePart = sledgehammer.PrimaryPart :: BasePart

		local weldConstraint: WeldConstraint = Instance.new("WeldConstraint")
		weldConstraint.Part0 = torso
		weldConstraint.Part1 = sledgehammerPrimaryPart
		weldConstraint.Parent = torso
		
		sledgehammer:PivotTo(torso.CFrame * CFrame.Angles(math.rad(45), math.rad(90), math.rad(90)))
		
		sledgehammer.Parent = character
	end
	
	player.CharacterAdded:Connect(onCharacterAdded)
end

players.PlayerAdded:Connect(onPlayerAdded)

What should happen?
Position the Sledgehammer at the torso like this:
image

The orientation of this sledgehammer is 45, 90, 90

What really happens:
image

The orientation of this sledgehammer is -0.001, 89.998, 134.996

Any idea why Roblox is ignoring my CFrame.Angles parameters? Please help!

Does it look different without using CFrame.Angles?

1 Like

What happens if you change CFrame.Angles to CFrame.fromEulerAnglesYXZ? I’m not sure if it’s enough to fix it but more of a curiosity.

Anyways, when using CFrame.Angles, the rotations are applied in reverse. So it first rotates Z by 90, then Y by 90, then X by 45. If you need to, you could break it up by using three separate CFrame.Angles calls to force X to be applied first.

2 Likes

CFrame.fromEulerAnglesYXZ seems to work, thank you!

1 Like

Same result as for CFrame.Angles.

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