How would I make this line of code work for mobile and console?

I found this in a free model and its the reason why my game doesn’t work on mobile or console. can anyone explain to me how I could fix it?

this is used in a camera script.

code:

	if inputObject.UserInputType == Enum.UserInputType.MouseMovement 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
1 Like

Use

RunService:BindToRenderstep

1 Like

I don’t understand.

here is more code if needed:

input.InputChanged:connect(function(inputObject)
	
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement 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)

I found out the reason why. It’s because mobile and console don’t have mouse movements, so I need to figure out a way to get thumbstick movement and screen movement

1 Like
local function update()
        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

game:GetService("RunService"):BindToRenderStep("CameraThing", 1, update)
2 Likes

I’m sorry but I don’t think you are understanding. I need the script to work for mobile and console.

also these answers seem very ai generated

2 Likes

you can use Enum.UserInputState.Changed instead of mouse movement i think

1 Like

Oh thanks everyone for the help, but I just realized the script completely broke another part of my game! I must now make a new system.

2 Likes

If you plan on trying to take input again for controller, though it’s from 2019, here’s a thread where various issues were tackled:

Make sure there’s a deadzone for controllers, Roblox at that time apparently had 0.2 for theirs. Maybe you want your vectors in your code to be zeros. Some info might be outdated, but hope that helps. Maybe C_Corpze can jump in here.

As for Touch, I’m not sure. There’s likely another thread on the forum for that. I’d assume you can use the TouchGui from Roblox (a screen gui only automatically added if the player has touch input). There’s the camera UI stuff in there. There’s probably a far better way though.

3 Likes

Oh thanks man! I found a different post going into detail on it. I had it working until

:slightly_smiling_face:

1 Like

As far as I know, joystick movement causes the .InputChanged even tot be fired.
To detect either the left or right joystick, one should simply only have to check what keycode it is.

function OnInputChanged(Input : InputObject, ignore : boolean)

	if     Input.KeyCode == Enum.KeyCode.Thumbstick1 then

		print("Left Stick: ", Input.Delta, Input.Position)

	elseif Input.KeyCode == Enum.KeyCode.Thumbstick2 then

		print("Right Stick: ", Input.Delta, Input.Position)

	end
end

This should do it basically, I’m pretty sure it still works to this day?

Position should give you a Vector that gives the exact analog position of the joystick in question.
While Delta should tell how fast it moved into a direction within a frame.

If I’m not mistaken the Delta value can change depending on frame rate but that’s just a theory, I have not tested that actually since I rarely ever use that.

Input systems might also just have their own update/tick cycle that is not tied to frame rate.

1 Like

I made these myself. I didn’t notice it needed the input object, so what you need is actually :GetMouse(). I took time out of my day to help you. I appreciate you saying that these are ai generated because now I am literally going to destroy everything in my sight now that you have said that. My day is ruined and my pain is immeasurable. I am losing my mind. But it is not me who is at fault for the destruction of my surroundings. It is yours. So be proud. Be proud of what you have accomplished

IMG_5127