Camera not working correctly

Hello, I have a problem with the camera, the fact is that it is custom and rotates in first person using a script, on desktop devices everything works well, but on mobile devices, something is wrong, the camera does not always rotate or may rotate slowly (the case not in variables).

UserInputService.TouchMoved:Connect(function(inputObject, gameProccesedEvent)
		if not gameProccesedEvent then
			local delta = Vector2.new(inputObject.Delta.X / Sensitivity,inputObject.Delta.Y / Sensitivity) * Smoothness -- everything ok with Smoothness 

			local X = TargetAngleX - delta.Y 

			TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
			TargetAngleY = (TargetAngleY - delta.X) % 360 
		end
end)

If you do not use gameProcessedEvent, then the camera rotates as it should, but the problem with this method is that the camera rotates even when you walk with the joystick, that is, by controlling the movement of the joystick, you also control the camera. How can I fix this?

1 Like

Try this:

local UserInputService = game:GetService("UserInputService")

local Sensitivity = 0.2
local Smoothness = 0.1

local TargetAngleX = 0
local TargetAngleY = 0

local touchStart
local isRotating = false

local function onTouchBegan(inputObject)
    touchStart = inputObject.Position
end

local function onTouchMoved(inputObject)
    if touchStart then
        local delta = (inputObject.Position - touchStart) * Sensitivity
        touchStart = inputObject.Position

        local X = TargetAngleX - delta.Y

        TargetAngleX = math.clamp(X, -80, 80)
        TargetAngleY = (TargetAngleY - delta.X) % 360

        isRotating = true
    end
end

local function onTouchEnded()
    touchStart = nil
    isRotating = false
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent then
        onTouchBegan(input)
    end
end)

UserInputService.InputChanged:Connect(function(input, gameProcessedEvent)
    if input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent and isRotating then
        onTouchMoved(input)
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Touch then
        onTouchEnded()
    end
end)

Adjust the Sensitivity value to control the camera rotation speed according to your preference.

1 Like

Unfortunately, the camera began to twitch more and not work correctly, but thanks for trying!

1 Like