Collapse Sidebar


The DeviceRotationChanged event fires when a user rotates a device that has a gyroscope.

A gyroscope is an component found in most mobile devices that detects orientation and rotational speed.

The event is useful when tracking the orientation of the device and how changes as the user rotates their device. To determine the current device rotation, you can use the UserInputService/GetDeviceRotation function.

To check if a user’s device has an enabled gyroscope, and that this event will fire, see UserInputService/GyroscopeEnabled.

This event only fires when the Roblox client window is in focus. For example, inputs will not be captured when the window is minimized.


Name Type Default Description

An InputObject providing info about the device’s rotation. InputObject/Position|InputObject.Rotation represents the new rotation in degrees and InputObject/Delta|InputObject.Delta represents the change in rotation in degrees

A CFrame representing the device’s current orientation

Code Samples

Create a Gyroscopic Camera

This example controls the player’s Camera so that it matches the player’s device orientation via using the device’s UserInputService/GyroscopeEnabled|gyroscope and UserInputService/AccelerometerEnabled|accelerometer.

The camera is positioned inside the player’s head, and updated to move with the player and the user’s device rotation, by executing the following line every RunService/BindToRenderStep|RenderStep:

		camera.CFrame = CFrame.new(head.Position - Vector3.new(0,8,10)) * currentRotation

The code sample relies on the device’s gyroscope to determine when the player rotates their device. It does so by connecting to the UserInputService/DeviceRotationChanged|DeviceRotationChanged event.

The code sample relies on the device’s accelerometer to retrieve the gravity vector used to determine the device’s orientation (whether it is flipped upside down or not). To determine whether the device’s orientation is upside down, the code sample uses the UserInputService/DeviceGravityChanged|DeviceGravityChanged event.

Since the script places the camera inside the head to create a first-person camera, the limbs are made transparent by the HideCharacter() function so that the player does not see their Player/Character when rotating the camera.

In order for this example to work as expected, it must be placed in a LocalScript and the user’s device must have a gyroscope and an accelerometer.

Move a Ball using the Accelerometer

This code adds a force on a part so that it falls in the direction of actual gravity relative to the user’s device. This code can be seen in this uncopylocked place.

In order for this example to work as expected, it must be placed in a LocalScript and the user’s device must have an UserInputService/AccelerometerEnabled|accelerometer.