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.
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