Mouse is always off-center on consoles

  1. What do you want to achieve? A mouse that can lock into the center like Enum.MouseBehavior.LockCenter, but on consoles.

  2. What is the issue? The mouse still stays off-center no matter what I do on consoles

  3. What solutions have you tried so far? Enum.MouseBehavior.LockCenter, but that only seems to work on PCs.

I know it’s possible to emulate the mouse click position using ViewportSize.X and Y / 2 and stuff, but I’d like a cleaner and easier way, that is, if it even exists.

My solution so far:

local center = cc.ViewportSize / 2
local mouseRay = cc:ViewportPointToRay(center.X, center.Y)
				
local result = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 500, RaycastParams.new())
				
local pos
				
if result == nil then
	pos = (mouseRay.Direction * 500)
else
	pos = result.Position
end
1 Like

I made this script, where if you hold down button you choose, it makes your cursor locked in the middle, and if you let go of it, you can move it freely again.

local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local bindEvent -- variable to store the bind

-- Player starts holding the button
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.ButtonL2 then -- Choose button based on your preference
		bindEvent = runService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
			userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		end)
	end
end)

-- Player stops holding the button
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.ButtonL2 then -- Should be same button as up there
		bindEvent = runService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
			userInputService.MouseBehavior = Enum.MouseBehavior.Default
		end)
	end
end)

I hope this will help you.

1 Like

what I meant is I’d like the mouse to be centered so that any Mouse.Hit.Position’s would be in the center of the screen, though I do already have a solution for that one, I want to know if there’s an easier way

1 Like