Camera not work (Mobile)

im making a camera system like Gta style but when i rotate it on mobile it doesnt rotate but it does have the shoulder cam tho

local xAngle = 0
local yAngle = 0
userInputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		xAngle = xAngle-input.Delta.x*0.4
		--Clamp the vertical axis so it doesn't go upside down or glitch.
		yAngle = math.clamp(yAngle-input.Delta.y*0.4,-20,20)
	end
end)
runService.RenderStepped:Connect(function()
	if Character and Character:FindFirstChild("HumanoidRootPart") then
      userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
				local rootPart = Character:WaitForChild("HumanoidRootPart")
				local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 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,-50000))
				Camera.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
   end
end

hope you can help me

Maybe try using ContextActionService since the user input is MouseMovement.

ok but doesnt that make things harder also i just say a even called userinputservice.TouchMoved could that help me?

That could probably work since that event is listening for touch events. Try it out and let me know if it works or not.

the only problem is i dont know how to figure out the which direction that player is moving if you help me that then i think i would be able to do it
i wanna somehow detect if the player is turning camera right left top or down

If you read through the article of this function, in the code example, it shows that you can record the player’s previous touch position, and their new touch position. Try using that.

1 Like

thx i figured out the math myself and got it working and its super smooth too

1 Like

hey seems like im having a problem here so basically whenever im moving my thumb to move player around i dont want the camera to move but idk how to fix i tried putting if not gpe then but still having the problem

Try checking if the player is running. This can be done through the humanoid. Here’s a quick example:

character.Humanoid.Running:Connect(function(speed)
  if speed > 0 then
    -- Code
  else
    -- Code
  end
end)

but wouldnt that make it that i cant turn camera while walking with my other finger?

Really depends on what you set the default cameras mode to. If you set it to scriptable, then yes, they wouldn’t be able to move the camera while walking (if you code it that way).

i made the camera as Custom only so i think it wouldnt affect i hope

OMG THANKS IT WORKED

1 Like