Weird mouse lock behavior

I have this camera module script that locks the mouse to the center of the screen when in first person. It works if the player mouse isnt locked beforehand, but if the mouse is already locked and the camera switches to first person, it unlocks the cursors.
When mouse isnt locked:

when mouse is already locked:

this is a big problem since the helicopter needs the mouse delta to control the yaw.

here’s the code snippet that changes the lock behavior:

elseif CameraType == CamManager.CameraTypes.FirstPerson then
		currentView = "FirstPerson"
		currentConfig = CreateConfig(CamManager.CameraTypes.FirstPerson)
		
		camera.CameraType = Enum.CameraType.Scriptable
		is.MouseBehavior = Enum.MouseBehavior.LockCenter

		rs:BindToRenderStep("FirstPerson", Enum.RenderPriority.Camera.Value, function()
			local newHead = currentConfig.Object.CFrame * CFrame.new(currentConfig.Offset)
			local pivot = newHead * CFrame.new(currentConfig.PivotOffset)
			local offset = pivot:Inverse() * newHead
			
			if currentConfig.LookAround then
				UpdateDelta(true)
			else
				ResetDelta()
			end
			
			pivot *= CFrame.Angles(0, math.rad(mouseX), 0) * CFrame.Angles(math.rad(mouseY), 0, 0)
			camera.CFrame = pivot * offset
		end)
end
1 Like

Is CameraType == CamManager … FirstPerson?

1 Like

its the module script using a table as an Enum for the camera types.

here’s how it would be called in a local script:

CManager.SwitchCamera(CManager.CameraTypes.FirstPerson)
1 Like

Yes, so what you’re saying is, that equals Enum.CameraTypes.FirstPerson?
And does CameraType equal that?

1 Like

my bad, here’s the full function:

function CamManager.SwitchCamera(CameraType)
	--hides head accessories
	HideAccessories(CameraType == CamManager.CameraTypes.FirstPerson, {"HatAttachment", "FaceFrontAttachment", "BodyFrontAttachment"})
	
	if CameraType == CamManager.CameraTypes.Default then
		currentConfig = {}
		if currentView == "FirstPerson" then
			rs:UnbindFromRenderStep("FirstPerson")
		end
		
		currentView = "Default"
		is.MouseBehavior = Enum.MouseBehavior.Default
		camera.CameraType = Enum.CameraType.Custom
		
		print("Default")	
	elseif CameraType == CamManager.CameraTypes.FirstPerson then
		currentView = "FirstPerson"
		currentConfig = CreateConfig(CamManager.CameraTypes.FirstPerson)
		
		camera.CameraType = Enum.CameraType.Scriptable
		is.MouseBehavior = Enum.MouseBehavior.LockCenter

		rs:BindToRenderStep("FirstPerson", Enum.RenderPriority.Camera.Value, function()
			local newHead = currentConfig.Object.CFrame * CFrame.new(currentConfig.Offset)
			local pivot = newHead * CFrame.new(currentConfig.PivotOffset)
			local offset = pivot:Inverse() * newHead
			
			if currentConfig.LookAround then
				UpdateDelta(true)
			else
				ResetDelta()
			end
			
			pivot *= CFrame.Angles(0, math.rad(mouseX), 0) * CFrame.Angles(math.rad(mouseY), 0, 0)
			camera.CFrame = pivot * offset
		end)
		
		print("First Person")
	else
		print("Invalid")
	end
	
	return currentConfig
end

the CameraType is the parameter

1 Like