Make sure Gamepad mouse go center

I making custom camera and testing for Gamepad but i got problems.
One of the problem is gamepad target(mouse?) goes other than the center.
Here is video.

This is not just a dot ui. It is a actual mouse thing!

This is a huge flaw for me trying to make an FPS game.
Script doing MouseBehavior.LockCenter on every RenderStepped but this happens.
Conversely, even if i set it to default, the result is the same.
What should i do? How to keep Gamepad mouse stay center?

.
.
And another problem is : I didn’t put anything in the script for movement, but I can’t control Character with Gamepad. Keyboard control working well.
I know it’s not good to post multiple questions in one post. Please focus on the first question above.

1 Like

As far as I’m aware there’s no way to fix this issue. The only thing I could think of is to make your own custom cursor for the gamepad by hiding the default cursor and using an imagelabel, and then doing raycasts from that point using ViewportPointToRay

1 Like

Can you show the entirety of the code segment? It might benefit you to bind some sort of camera code to ContextActionService so that when the player moves the mouse it’ll execute some code… Following is a segment of code I used to accomplish the same goal:

function MovementClient:SetMouse(locked) --If locked == false, we can move the mouse around (Important for menus to work.)
	if locked then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		UserInputService.MouseIconEnabled = false
	else
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		UserInputService.MouseIconEnabled = true
	end
end

function MovementClient:CameraSetup(enabled)
	if enabled then
		workspace:WaitForChild("Camera")
		MovementClient:SetMouse(true)
		local angle_x = 0
		local angle_y = 0
		local cameraPos = Vector3.new(3.5,1.1,9) -- Vector3.new(2.8,1.1,9)
		ContextActionService:BindAction("MouseCameraMovement", function(_,_,input)
			if input.UserInputType == Enum.UserInputType.MouseMovement then
				angle_x = angle_x - input.Delta.x*0.4
				angle_y = math.clamp(angle_y - input.Delta.y*0.4, -80, 80)
			elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
				angle_x = angle_x - input.Delta.X*0.4
				angle_y = math.clamp(angle_y+input.Delta.Y*0.4, -80, 80)
			end
		end, false, Enum.UserInputType.MouseMovement, Enum.KeyCode.Thumbstick2)
		
		--[[ContextActionService:BindAction("ControllerCameraMovement", function(_,_,input)
			angle_x += -input.Delta.x * 360
			angle_y += -input.Delta.y * 360
		end, false, Enum.KeyCode.Thumbstick2)
	]]
		RunService:BindToRenderStep("CameraController", Enum.RenderPriority.Camera.Value +1, function()
			if Character then
				--print(angle_x, ", ", angle_y)
				local startCFrame = CFrame.new(Character.HumanoidRootPart.CFrame.p) * CFrame.Angles(0, math.rad(angle_x), 0) * CFrame.Angles(math.rad(angle_y), 0, 0) --CFrame.Angles(0, math.rad(angle_x), 0) * CFrame.Angles(math.rad(angle_y), 0, 0)
				local cameraCFrame = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
				local cameraFocus = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, -100000))
				workspace.CurrentCamera.CFrame = CFrame.new(cameraCFrame.p, cameraFocus.p)
				if not WallRunning then
					Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.p, Character.HumanoidRootPart.CFrame.p + Vector3.new(workspace.CurrentCamera.CFrame.LookVector.X, 0, workspace.CurrentCamera.CFrame.LookVector.Z))
				end
			end
		end)
	end
end

This code obviously includes some variables that you probably don’t need, such as wallrunning, but it features an over the shoulder camera angle. Modifying it slightly should yield the results you need. Make sure you only set MouseBehavior once though, not on every frame.