CFrame help with relative/local rotations along an axis

I want to know the local rotation angle of a part’s CFrame, say the Z rotation along that axis. I’ve been using the :toEulerAngles() method, but it does not give the local Z rotation as I desire.

For my example, say I want to know the rotation angle of the chassis in the direction of the arrows I drew in the picture, no matter what direction I am facing. How would I achieve this with CFrame math? Thanks!

angles

1 Like

As a pre-requisite to what you’re trying to achieve - apologies if I misintepretted what you’re explaining - you’ll need to understand transformation matrix and I’m assuming you have knowledge of CFrame.

If you’re looking for an accurate value, I don’t recommend using Euler angles in this circumstance as it will not give you the result you’re looking for.
There’s a wiki article which explains why this isn’t a good idea, it also may assist you in finding your answer.

2 Likes

I understand what the euler angles do and in general how the CFrame math works in terms of matrices, but the intricacies of CFrame:toObjectSpace() transforms still daunt me. I’ve been playing around with the Euler angles that I get and found that one part with a CFrame of local y axis rotated by 60 degrees does not have 60 degrees more on the y value for the :toEulerAngles() output if the original part in most cases. Hopefully I’m not too confusing.

1 Like

Have you watched this video?


Note that with CFrame:ToObjectSpace(cFrame), the narrator incorrectly describes cFrame as being the origin—the values are actually the other way around, with the CFrame being the origin.

Correct me if I am wrong, but it sounds like you want to find the angle between the local x axis and the global y axis. This can be done with a simple dot product:

local y = Vector3.fromAxis(Enum.Axis.Y)
local function getRoll(part)
	local x = part.CFrame.RightVector
	return x:Dot(y)
end

Let me know if that works

3 Likes

Hmm, that deconstruction works as well, I believe. Thanks!

1 Like