Help with first person camera

For some reason I can’t look on the y-axis but I can look on the x-axis which makes zero sense even though I wrote code to implement those features (I have my camera type set to scriptable).

Input.InputChanged:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local Delta = Vector2.new(InputObject.Delta.x / Sensitivity, InputObject.Delta.y / Sensitivity) * Smoothness

		local X = TargetAngleX - Delta.y 
		TargetAngleX = math.clamp(X, -80, 80)
		TargetAngleY = (TargetAngleY - Delta.x) % 360
	end
end)

I do however have another script that sets my cameras CFrame to the players head. I have zero clue if this overrides looking on the y-axis but I’m still able to look on the x-axis (It achieves a great effect which is why I’m doing it this way).

local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local head = character:WaitForChild("Head")
local humanoid = character:WaitForChild("Humanoid")

local function isPlayerMoving()
	local velocity = character.HumanoidRootPart.Velocity
	return velocity.magnitude > 1
end

local function lookOnY()
	-- a function that does nothing (it makes sense to me).
end


-- a terrible solution so I can at least look on the y-axis when not moving (not a fix).
runService.RenderStepped:Connect(function(deltaTime)
	if isPlayerMoving() then
		camera.CFrame = head.CFrame
	else
		lookOnY() -- does nothing but, it does actually allow me to be able to look on the y-axis when not moving (function is not needed for it to work though).
	end
end)

Video of my camera system:

Is what I’m trying to do even possible? If anyone has any knowledge about cameras and how they work that would be great!

1 Like

There is a decent Open Source Camera Module that looks like it might do exactly what you are trying to (locked camera with full view to look around & key to “unlock” for clicking) made by AllYourBlox you can check out. Code For Video - Pastebin.com
[Not 100% if that post is up to date but you can peek and see if what you are missing is referenced there.] It goes side-by-side with a separate Control Module, if you dont see something helpful maybe look him up. Goodluck!

1 Like

so, when the camera is attached to the players head cframe it has this cool dynamic/immersive effect, the camera follows the heads animations, etc. I can look on the x-axis but not the y-axis. I have zero clue if this is on robloxs limitations or what but my code does allow for mouse movement on the y-axis which is weird.

heres the code that allows mouse movement in first person:

Input.InputChanged:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local Delta = Vector2.new(InputObject.Delta.x / Sensitivity, InputObject.Delta.y / Sensitivity) * Smoothness

		local X = TargetAngleX - Delta.y 
		TargetAngleX = math.clamp(X, -80, 80)
		TargetAngleY = (TargetAngleY - Delta.x) % 360
	end
end)

Nevermind, I finally found a solution.

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