Rotate a cframe on axis

I’m trying to rotate a CFrame on the Y axis, but I don’t want it to rotate based on the rotation of the x axis like CFrame.Angles would do. Is there any way I could do this?

Have you searched the forum first?

On its Y axis or the world Y axis? These are 2 different things.
If you tried a script please post it.

I searched ‘CFrame on a part axis’ and found a bunch of posts like:


I think this is what im going for, ill see if it works

It kind of works. but now I have other problems because of it

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local UIS = game:GetService("UserInputService")
cam.CameraType = Enum.CameraType.Scriptable
local lastCF = nil

	local delta = UIS:GetMouseDelta()
	local x,y,z,r0,r1,r2,r10,r11,r12,r20,r21,r22 = cam.CFrame:GetComponents()
	cam.CFrame =,head.Position.Y,head.Position.Z,r0,r1,r2,r10,r11,r12,r20,r21,r22)
	delta =,-100,100),math.clamp(delta.Y,-100,100))
	local cf = cam.CFrame * CFrame.Angles(-math.rad(delta.Y),0,0)
	cf = CFrame.Angles(0,-math.rad(delta.X),0) * (cf - cf.Position) + cf.Position
	if delta ==,0) and lastCF then
		cam.CFrame = cam.CFrame:Lerp(lastCF,.05)
		cam.CFrame = cam.CFrame:Lerp(cf,.1)
		lastCF = cf
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

im making a custom first-person script and it works but when you move your mouse too fast the camera rotates on its side and im not really sure why, since the cframe should be rotating on the world y axis

The CFrame should be in world space I think.

I still have this problem even when I change both to worldspace

You should do this to the CFrame:

cf = CFrame.lookAt(cf.Position, cf.Position + cf.LookVector)

Sorry to bother you again, but I noticed a problem where if you look to the sides at a 90-degree angle, you cant look up and down, and when you look behind you, the up and down controls are in reverse for some reason.

Weird. This is a problem with something to do with object/world space.
Just do something like local cf = CFrame.Angles(-math.rad(delta.Y), -math.rad(delta.X), 0):ToObjectSpace(cam.CFrame) and delete the other angles line.

It seems to be the same problem, I have no idea where its coming from

try instead of :ToObjectSpace(cam.CFrame) do :ToObjectSpace(head.CFrame), and the head being either the head of the character or the root of the character.

Pretty sure it’s called Gimbal Lock because of the way CFrames work
Try this post:

1 Like

Do you know how I would prevent gimbal lock? The post just says not to use Euler angles but it doesn’t say what to do instead.

It tells you the script to convert to a rotation matrix.
Have you tried using the Search tool or an internet search to find an answer.