CFrame.Angles not returning correct value in Motor6D

So, I was doing my Viewmodel system and I was trying to do a system for the Tool position and orientation at the viewmodel.

I tried to use CFrame.Angles and CFrame.fromEulerAnglesXYZ() but yeah, still getting the wrong Orientation.

This is the part of the script that changes the Motor6D C0 Orientation

local X, Y, Z = VMModel:WaitForChild("Handle"):WaitForChild("GripWeldValue"):GetAttribute("X"), VMModel:WaitForChild("Handle"):WaitForChild("GripWeldValue"):GetAttribute("Y"), VMModel:WaitForChild("Handle"):WaitForChild("GripWeldValue"):GetAttribute("Z")
		
	local weldCFrame = CFrame.new(Vector3.new(0, 0, 0)) * CFrame.Angles(math.rad(WeldValue.Position.X), math.rad(WeldValue.Position.Y), math.rad(WeldValue.Position.Z))
	weldCFrame = weldCFrame + Vector3.new(0, -0.3, 0) -- ajuste de posição para se encaixar melhor com a mão do personagem
	weldCFrame = weldCFrame * CFrame.Angles(math.rad(60), math.rad(-90), math.rad(120))
	Weld.C0 = weldCFrame
  • The X, Y and Z are Attributes of the CFrame value in the script.
    Also, instead of using them, I tried to put the numbers, but i got the same result after all.
    The Orientation Attribute is not being used
    image

Here’s a visual demonstration of the error

.

Any help is welcome!

Use fromOrientation instead of Angles. Angles applies Z rotation first, which is backwards.

Whenever you get time, I recommend learning matrices or quaternions for rotation. XYZ rotations do not contain enough data to describe rotations and are here only for convenience. As such, xyz rotations are subject to oddities and anomalies.

3 Likes

Thank you, it works fine now.
Now i am getting 59.496, 89.151, 119.015, which is the approximated value that I needed.

I need to actually, since i’ve seen a lot of anomalies from xyz rotations, in near future i’ll try to port this to matrices or quaternions.

1 Like

.Angles() applied in Z, Y, X order, not X, Y, Z.

You should use .fromOrientation() or .fromEulerAnglesYXZ() for X, Y, Z order, what @JarodOfOrbiter said.

1 Like

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