How do I snap the Z Axis on this align orientation?

Hi Programmers! I require your assistance with an AlignOrientation (presumably CFrame error). So, in my align orientation everything seems to work fine- the A.O’s
CFrame is set to follow the player’s mouse.

I seem to notice that it does indeed rotate left and right following the mouse on the Y Rotation Axis but it also seems to be rotating slightly (but not all the way (?) ) up & down ( Z Rotation Axis). Would anyone help me in making the Z Axis not change, only the Y axis (left and right)

My goal:

  • Follow the mouse and rotate the HumanoidRootPart on the Y Axis :white_check_mark:
  • The HumanoidRootPart does not move up and down on the Z Axis :x:

CLIENT INVOKE SCRIPT

EventFolder:WaitForChild("GetMouse").OnClientInvoke = function()
	local Mouse = Player:GetMouse()
	local TORETURN = Mouse.Hit
	return TORETURN
end

SERVER SCRIPT

RUN_SERVICE.Heartbeat:Connect(function(dT)
		
		local MOUSE = EVENT_FOLDER:WaitForChild("GetMouse"):InvokeClient(PLAYER)
		 	
		ALIGN_ORIENTATION.CFrame = MOUSE
		
		print("SET")
		
		task.wait()
		
	end)

Any help would be appreciated! Thank you.

You could probably negate the X and Z rotation axes from the goal CFrame.

local _, y = mouse:ToOrientation()
alignOrientation.CFrame = CFrame.new(mouse.Position) * CFrame.Angles(0, y, 0)
1 Like

Heya! the first one seemed to work. The second block didn’t work though, thank you so much for your help!

1 Like

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