Why does the camera glitch like this?

I am making a custom camera for my horror game but the camera keeps glitching, this is the code i am currently using:


--Camera Manipulation
local X, Y, AngleX, AngleY = 0,0, CFrame.Angles(0,0,0), CFrame.Angles(0,0,0) -- Base values 

local Offset = CFrame.new(0, 0.25, 1.25) * CFrame.Angles(0, math.rad(180), 0) -- You might want to change this to suit your game better 

function Update()
	head.CanCollide = false
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	camera.CameraType = Enum.CameraType.Scriptable 
	local Delta = uis:GetMouseDelta() -- Get change in mouse position 

	X = X + (Delta.X*0.15) -- Set X value accordingly (mouse left/right)
	Y = math.clamp(Y + (Delta.Y*0.15),-89.99,89.99) -- Set value Y value accordingly (mouse up/down, clamped to prevent glitch where camera rotates at 90) 

	AngleX = CFrame.Angles(0, math.rad(-X), 0) -- Create angles using X on Y 
	AngleY = CFrame.Angles(math.rad(-Y),0,0) -- Create angles using Y on X 

	camera.CFrame = CFrame.new((character.Head.CFrame).p) * AngleX * Offset * AngleY

	local Position = character.HumanoidRootPart.CFrame.p -- Set to the root part's position 
	local GoalRotate = CFrame.new(Position, camera.CFrame.Position) -- Faces the camera from the root part's position 
	local _, RotY, _= GoalRotate:ToOrientation() -- Stores the Y orientation value, which we will then use in CFrame.fromOrientation to set the X and Z to 0, limiting it to Y (rotating side to side)  

	character.HumanoidRootPart.CFrame = CFrame.new(Position) * CFrame.fromOrientation(0, RotY, 0) 
end


--RunService
rs:BindToRenderStep("CameraUpdate",Enum.RenderPriority.Camera.Value, Update) 

(I set head CanCollide Property to false because i thought that was the problem)

Video:

I believe its to do with AngleX and Y because its creating a new angle everysingle time could you send a video of you walking straight forward.

Does your objective have to do with forcing the camera to first person? If so, you can just force it by setting the CameraMode in StarterPlayer, or through a LocalScript.
image

And to make the body parts visible, check the character’s parts using a for i, v in pairs() loop, and set each part’s LocalTransparencyModifier to 0.

wait()
local player = game.Players.LocalPlayer
local character = player.Character
player.CameraMode = Enum.CameraMode.LockFirstPerson

for i, v in pairs(character:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Head" then
        v.LocalTransparencyModifier = 0
		v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			v.LocalTransparencyModifier = v.Transparency
		end)
	end
end
1 Like

its most likely cause your running that camera to those exact vectors every frame with run service.

These are all solutions i have tried none of them seemed to work

When i walk forward it does the exact same thing

It probably is, have any solutions?

1 Like