Make part face Y axis of the mouse

workspace.Example.CFrame = CFrame.new(workspace.Example.Position,Vector3.new(workspace.Example.Position.X,pos.Y,workspace.Example.Position.Z))

Im trying to make the part go face the Y Axis of the mouse but its not working, the part wont rotate at all, I also tried

workspace.Example.CFrame = CFrame.new(workspace.Example.Position,Vector3.new(0,pos.Y,0))

But the parts X and Z axis becomes 0 which is ineffecient since I only want the Y Axis to change.

1 Like

I assume by Y axis, you mean the up / down rotation. If not, this would still apply, though.

You can simply use the method CFrame:ToOrientation() to return a tuple (3 approximate angles representing the rotation for each axis) and only take use of the rX (up/down) rotation from the LookAt CFrame while preserving the rZ (tilt left/right) and rY (left/right) rotations from the Part’s CFrame.

Example:


local rX, _, _ = CFrame.new(Part.CFrame.p, Mouse.Hit.p):ToOrientation() -- For reference, this is the LookAt CFrame
local _, rY, rZ = Part.CFrame:ToOrientation()

Part.CFrame = CFrame.new(Part.CFrame.p) * CFrame.fromOrientation(rX, rY, rZ)

2 Likes