How To Set Individual CFrame Axis

Hello, I am completely stumped with trying to implement a function that copies the rotation from one part but sets the z rotation to 0.

For example

local part1 = game.Workspace.Part1 
local part2 = game,Workspace.Part2 

-- What I want to do 
part2.CFrame = CFrame.new(part2.Position) * CFrame.Angle(part1.XRotation, part1.YRotation, 0) 

I know that isn’t how the Angle method is used but it is the easiest way I can think of explaining it. I have been stuck on this for a while now messing with quaternion values and different vector arithmetic but was curious if anyone had a simple solution to this that I probably missed?

I just want part2 to match part1’s rotation except for the Z axis that should be 0.

Thank you!

Solution:

It was sitting in front of my face the entire time

local x1, y1, z1 = part1.CFrame:ToOrientation()
part2.CFrame = CFrame.new(part2.Position) * CFrame.Angles(x1, y1, 0)

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