(Android) Does The Gyroscope And Accelerometer Not Work?

I wanted to test a new project with the Gyroscope and Accelerometer, but my attempts aren’t going well.

local UserInputService,RunService = game:GetService("UserInputService"),game:GetService("RunService")

RunService.RenderStepped:connect(function(Delta)
	local FPS = 1/Delta
	local GyroscopeEnabled = UserInputService.GyroscopeEnabled
	local AccelerometerEnabled = UserInputService.AccelerometerEnabled
	local _,Gyro = UserInputService:GetDeviceRotation()
	local Acceleration = UserInputService:GetDeviceAcceleration().Delta
	script.Parent.Text = "FPS: "..FPS.."\nGyroscope (Enabled: "..tostring(GyroscopeEnabled).."): "..tostring(Gyro).."\nAccelerometer (Enabled: "..tostring(AccelerometerEnabled).."): "..tostring(Acceleration)
end)

They are only returning blank values. This was confirmed on 2 devices (my Samsung Galaxy S7, and my NVIDIA SHIELD K1 tablet), both running Android 6.0.1.

3 Likes

Well I figured that out quickly… appears that the events work but the functions don’t.

[code]
local UserInputService,RunService = game:GetService(“UserInputService”),game:GetService(“RunService”)

local Gyro,Acceleration = Vector3.new(),Vector3.new()
RunService.RenderStepped:connect(function(Delta)
local FPS = 1/Delta
local GyroscopeEnabled = UserInputService.GyroscopeEnabled
local AccelerometerEnabled = UserInputService.AccelerometerEnabled
–local _,Gyro = UserInputService:GetDeviceRotation()
–local Acceleration = UserInputService:GetDeviceAcceleration().Delta
script.Parent.Text = "FPS: “…FPS…”\nGyroscope (Enabled: “…tostring(GyroscopeEnabled)…”): “…tostring(Gyro)…”\nAccelerometer (Enabled: “…tostring(AccelerometerEnabled)…”): "…tostring(Acceleration)
end)

UserInputService.DeviceRotationChanged:connect(function(Input,_)
Gyro = Input.Position
end)

UserInputService.DeviceAccelerationChanged:connect(function(Input,_)
Acceleration = Input.Position
end)[/code]

1 Like

Should make a bug report about the functions that return defaults (apparently?)

I recall using these before and they worked though.

Currently the functions won’t work until you connect to the events. This was sort of done on purpose so we don’t continuously poll the motion sensors if you aren’t using them. I’ll try and update the functions to turn on the sensor polling. Thanks for the report!

3 Likes

ok have an easy fix for this, should ship in the next couple of weeks.

2 Likes

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