How do device functions of UserInputService work?

Okay.

How does the GetDeviceRotation, GetDeviceAccelerationand GetDeviceGravity work?

I tried testing it in Roblox however my the output said that there is no Accelerometer in my phone.

There definitely is.

It is the same story with Gravity and Rotation.

Is there a setting I have to set or something I have to do so that I can get these values? Is it a problem with Roblox

Just FYI I have a MI Redmi 6

And I testing with same results a Huawei Mediapad T5

1 Like

Try creating a separate LocalScript running something like this:

local UIS = game:GetService("UserInputService")
UIS.DeviceAccelerationChanged:connect(function(Acc)
	script.Parent.Text = tostring(Acc.Position)
end)
1 Like

Thanks. I did do that and yes it did work. However it didn’t work for the gyroscope.

Do you know how I can check whether or not I have a gyro thanks

I kinda need it because I am trying to make a car that you can control by tilting you phone

I have checked on my device specifications and it says it has a gyroscope. Do you have any idea why it does not work?

The soloution to your answer.

GetDeviceAcceleration

The GetDeviceAcceleration function determines the current acceleration of the user’s device. It returns an InputObject that describes the device’s current acceleration.

In order for this to work, the user’s device must have an enabled accelerometer. To check if a user’s device has an enabled accelerometer, you can check the UserInputService.AccelerometerEnabled property.

If you want to track when the user’s device’s acceleration changes instead, you can use the UserInputService.DeviceAccelerationChanged event.

Since it only fires locally, it can only be used in a LocalScript .

GetDeviceRotation

This function returns an InputObject and a CFrame describing the device’s current rotation vector.

This is fired with an InputObject. The Position property of the input object is a Enum.InputType.Gyroscope that tracks the total rotation in each local device axis.

Device rotation can only be tracked on devices with a gyroscope .

As this function fires locally, it can only be used in a LocalScript .

GetDeviceGravity

This function returns an InputObject describing the device’s current gravity vector.

The gravity vector is determined by the device’s orientation relative to the real-world force of gravity. For instance, if a device is perfectly upright (portrait), the gravity vector is Vector3.new(0, 0, -9.18) . If the left side of the device is pointing down, the vector is Vector3.new(9.81, 0, 0). Finally, if the back of the device is pointing down, the vector is Vector3.new(0, -9.81, 0).

This function might be used to enable the user’s device to impact or control gravity within the game or move in-game objects such as a ball.

Gravity is only tracked for players using a device with an enabled gyroscope - such as a mobile device.

To check if a user’s device has an enabled gyroscope, check the value of UserInputService.GyroscopeEnabled . If the device has an enabled gyroscope, you can also use the UserInputService.DeviceGravityChanged event to track when force of gravity on the user’s device changes.

As UserInputService is client-side only, this function can only be used in a LocalScript .

Source:

https://developer.roblox.com/en-us/api-reference/class/UserInputService

I hope this helps and have a good day!

DM me if you have any questions!

2 Likes

That doesn’t exactly help.

I want to know why the gyroscope on my phone is not being detected by Roblox.

I answered your first question about:

How does the GetDeviceRotation, GetDeviceAccelerationand GetDeviceGravity work?

That is all, I am not sure why the gyroscope on your phone is not being detected by Roblox.

1 Like