How to limit CFrame rotation on a specific axis

I am trying to make a cannon/part face towards the player’s mouse, but only on the y axis. It can currently turn a full 360 degrees. I want to make it so that it has limited turning.

How would I go about this?

local RNS = game:GetService("RunService")
local PS = game:GetService("Players")

local player = PS.LocalPlayer
local Mouse = player:GetMouse()
local part = workspace:WaitForChild("Cannon"):WaitForChild("Cannon")

	local pos =, part.Position.Y, Mouse.Hit.Position.Z)
	part.CFrame =, pos)
1 Like

I haven’t tested this but maybe try setting the x and z axis to what it is is set to while not running or whatever, so that is would still detect and change the y axis (again I’m not in studio so I’m not sure if this will work)

I ended up figuring it out on my own, I just need to check to max sure the Y orientation wasn’t greater than -135 and also was less than 135. And if it was, it would just set the orientation to, -135, 0)

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