How I can convert CFrame to Orientation Vector3?

Hello guys. I’m making my plugin. I almost finished rotational handles, but got one problem:
this handles work with CFrames, while people should input plane’s ROTATION (vector3) into 3-input slots:
image

When I try to convert CFrame to rotation, it work only sometimes. In most cases, it goes crazy, have inverted rotation, etc.

Can someone tell me, how I can convert CFrame to Rotation, and back properly?

1 Like

I don’t entirely understand why you need to convert CFrame to rotation and back, so let me know if I didn’t quite answer your question.

CFrames are comprised of a position vector and a 3x3 rotation matrix for a total of 12 values. To obtain the position/rotation values of a CFrame you can use CFrame.Position or CFrame.Rotation. If you want all 12 values, you can use CFrame:GetComponents(). One thing to note, which may be your issue, is that CFrame.Rotation does not return a vector. CFrame.Rotation returns “a copy of the CFrame with no translation.” If you didn’t already know, you would normally apply rotation by multiplying CFrame.Angles. Since this is already a CFrame, you can just multiply it outright. Here’s how that would look when copying a CFrame to another part after separating position and rotation.

local currentPosition = workspace.Part1.CFrame.Position
local currentRotation = workspace.Part1.CFrame.Rotation
workspace.Part2.CFrame = CFrame.new(currentPosition) * currentRotation

As for applying rotation values that a user inputs, you’ll want to multiply CFrame.Angles. That would look like the following.

local currentPosition = workspace.Part.CFrame.Position
local xInput, yInput, zInput = 30, 60, 90
workspace.Part.CFrame = CFrame.new(currentPosition) * CFrame.Angles(xInput, yInput, zInput)

You can also leave out the position and just keep CFrame.Angles, since it’s the same.

local xInput, yInput, zInput = 30, 60, 90
workspace.Part.CFrame = CFrame.Angles(xInput, yInput, zInput)

Hope that helps! Feel free to reply if I misunderstood and/or didn’t fully answer your question.

1 Like

Hello, thank for this explanations (but I need diffirent thing)

I have this handles for rotating object:
image
They work with CFrame of plane (that white orb)

Also I have manual value inputs:
image
Which should behave like this built-in params (yellow dots):
image

Both this tabs control how Plane will be locked in workspace, so if there’s Position 0, 60, 30 and rotation 30, 0, 0, plane center will be locked to CFrame (0, 60, 30, 1, 0, 0, 0, 0.866025388, -0.5, 0, 0.5, 0.866025388)

When I try rotate smth with my handles, it should show resulted rotation in this Rotation tab.

But when I try make this, I run into problems where I incorrectly transform CFrame’s Rotation into Orientation Vector3, which result in incorrect plane:
image

(you can see here that grid plane is in incorrect rotation, after rotating white orb with handles, that’s because I incorrectly calculated Orientation Vector3, which I utilize in plane positioning)

So you’re trying to make the plane have the same rotation as the object? Can you provide examples of your code?

If I understand correctly, you’re trying to have the grid be in line with the white orb?

Wouldn’t it then not be easier to just grab the orb’s CFrame, and then offset it by the distance you want the grid to be?

grid.CFrame = orb.CFrame * CFrame.new(0,0,5)

After long look into my code, I solved my problem. It was caused by this:
image
I mixed CFrame.Angles() with Orientation Vector3, which inputted in that 3-inputs. Because of their diffirence in rotation order, I got incorrect results.

Glad to hear that you got the issue resolved! Be sure to make the post as resolved, so others with the same question can learn from it too.

1 Like

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