Tablet vs Phone Orientation

Hello, I am making tilt controls for my mobile game, and I stumbled across an issue that is very strange, as I thought all mobile devices gave the same input.

I wanted to measure how much the device was being turned only in the x axis.

if gyroEnabled then
	local _inputObj, cframe = UserInputService:GetDeviceRotation()
	if math.round((cframe.ZVector.X * 10)) < 2 and math.round((cframe.ZVector.X * 10)) > -2 then
		--off
	elseif math.round((cframe.ZVector.X * 100)) > 7 then
		--left on
	elseif math.round((cframe.ZVector.X * 100)) < -7 then
		--right on
	end
else
	print("Cannot get device rotation because device does not have an enabled gyroscope!")
end

When I test a phone, turning the device to the left causes the cframe.ZVector.X to be positive, and right is negative. However, when I test on a tablet, turning left causes it to be negative, and right positive.

I am unsure why this is, does anyone know why?

1 Like

Have you tried turning the tablet upside down?

1 Like

In case you had, you can add an “Invert Controls” option, or a selection when you join the game on a mobile device.

1 Like

Yeah, it does the same thing. I even locked every device to Landscape Right.

1 Like

I am trying to figure out why though, is it every tablet, or just iPad, is it every phone, or just a certain kind.

1 Like

As I said, you can add an “Invert controls” option, see if that works.

True, but I would want to do that automatically, so how can roblox tell between a phone or iPad when someone joins is what I am wondering.

Sorry! been sick.
You could check the aspect ratio, using ViewportSize!!

local Ratios = {
{960, 640, "iPhone 4"}
} -- put ratios for a buncha devices here (i put an example)
local ScreenX =  workspace.CurrentCamera.ViewportSize.X
local ScreenY =  workspace.CurrentCamera.ViewportSize.Y
local Device

for i,v in pairs(Ratios) do
    local X,Y = v[1],v[2]
    if (ScreenX == X or ScreenX == Y) and (ScreenY == X or ScreenY == Y) then
        Device = v[3]
    end
end

Hope this helps!