Camera movement for mobile

Hello! I need some help. I have scripted a working camera movement that only really works for PC. I’m not sending the whole code, but here’s partial code that basically controls the camera movement. I even tried commenting it out and I know it’s definitely this code. When I commented it out, I couldn’t move my camera on PC. I want to achieve where it works for mobile too. On mobile, the camera can’t move and I want this script compatible with mobile too. Here’s the script. If anyone who’s experienced with this could help me, that’d be awesome! Thanks.

This is partial of the whole main code. But the other code really just controls other stuff like movement speed and stuff. The code I sent is what controls the camera movement. How can I make it support mobile movement too?

local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0

input.InputChanged:connect(function(inputObject)

	if inputObject.UserInputType == Enum.UserInputType.MouseMovemen then
		local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * 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)

append this:
or inputObject.UserInputType == Enum.UserInputType.Touch

1 Like

I tested it out and it works, but it also moves the camera when I use the thumbstick move thing. What should I do here?

You need to add a 2nd parameter to your input began. It’s called gameProcessedEvent, and it’s true if the game processed it (like a button click). If it’s true, you should return end.

Ok I’m testing gameProcessed out really quick, I’ll update you on what happens. Thanks for replying by the way! I really appreciate it.

It works! Thank you so much for this help, I’ve been trying to figure it out for so long. Much appreciated! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.