Type Index Pages
- BillboardGui
- CanvasGroup
- Frame
- Hint
- ImageButton
- ImageLabel
- PlayerGui
- ScreenGui
- ScrollingFrame
- StarterGui
- SurfaceGui
- TextBox
- TextButton
- TextLabel
- UIAspectRatioConstraint
- UIGradient
- UIGridLayout
- UIListLayout
- UIPadding
- UIPageLayout
- UIScale
- UISizeConstraint
- UITableLayout
- UITextSizeConstraint
- VideoFrame
- ViewportFrame
- ChangeHistoryService
- CoreGui
- DataModelSession
- DockWidgetPluginGui
- MultipleDocumentInterfaceInstance
- Plugin
- PluginAction
- PluginGui
- PluginGuiService
- PluginManager
- PluginMenu
- PluginMouse
- PluginToolbar
- PluginToolbarButton
- QWidgetPluginGui
- Selection
- StandalonePluginScripts
- StatsItem
- StudioService
- StudioTheme
No results found!
-
Instance
- GameSettings
- DebugSettings
- BodyMover
- WeldConstraint
- HttpRbxApiService
- NotificationService
- Translator
- Lighting
- Beam
- GuiService
- UserInputService
- Studio
- Plugin
- HttpService
- Mouse
- BindableEvent
- RunService
- Pages
- Humanoid
- TestService
- PathfindingService
- Chat
- NetworkPeer
- Feature
- CharacterAppearance
- Constraint
- NetworkReplicator
- JointInstance
- Light
- BasePlayerGui
- AnalyticsService
- NetworkMarker
- BinaryStringValue
- FlyweightService
- Geometry
- LoginService
- InstancePacketCache
- ThirdPartyUserService
- TouchInputService
- RuntimeScriptService
- GuidRegistryService
- PartOperationAsset
- DialogChoice
- PhysicsService
- AdService
- TextService
- MarketplaceService
- TeleportService
- Accoutrement
- GamePassService
- AssetService
- InsertService
- PointsService
- ChangeHistoryService
- ServerScriptService
- JointsService
- LogService
- InputObject
- Toolbar
- LuaSettings
- RenderSettings
- AnimationTrack
- PhysicsSettings
- NetworkSettings
- CFrameValue
- Animation
- Color3Value
- BoolValue
- BrickColorValue
- Vector3Value
- AnimationController
- BindableFunction
- Button
- Trail
- LocalizationTable
- LocalizationService
- DebuggerBreakpoint
- DebuggerWatch
- ScriptDebugger
- Animator
- Attachment
- RemoteFunction
- RemoteEvent
- PluginManager
- Camera
- Stats
- Sky
- StarterPlayer
- Dragger
- TerrainRegion
- Path
- TextFilterResult
- Dialog
- StatsItem
- GoogleAnalyticsConfiguration
- ScriptContext
- ControllerService
- CacheableContentProvider
- ReflectionMetadataClasses
- ReflectionMetadataEnums
- DebuggerManager
- GuiBase
- UIBase
- LuaSourceContainer
- GuiItem
- DataModelMesh
- ServiceProvider
- ReflectionMetadataItem
- PostEffect
- PhysicsPacketCache
- TouchTransmitter
- RobloxReplicatedStorage
- Visit
- LuaWebService
- ScriptService
- FlagStandService
- VirtualUser
- SpawnerService
- TimerService
- CookiesService
- Team
- GroupService
- StarterGear
- Message
- PlayerScripts
- Configuration
- ContentProvider
- CollectionService
- Debris
- ReplicatedFirst
- ServerStorage
- ReplicatedStorage
- Folder
- TweenService
- Players
- ContextActionService
- StarterPlayerScripts
- SoundService
- KeyframeSequenceProvider
- VRService
- PluginGuiService
- Player
- Teams
- Pose
- Keyframe
- KeyframeSequence
- IntConstrainedValue
- DoubleConstrainedValue
- ForceField
- RayValue
- Fire
- Smoke
- Sparkles
- ParticleEmitter
- IntValue
- StringValue
- NumberValue
- Explosion
- ObjectValue
- SoundGroup
- UserGameSettings
- ClickDetector
- Sound
- Selection
- BadgeService
- TaskScheduler
- GlobalDataStore
- DataStoreService
- CustomEvent
- CustomEventReceiver
- VirtualInputManager
- FunctionalTest
- TweenBase
- SoundEffect
- ReflectionMetadataEvents
- ClusterPacketCache
- PVInstance
- FaceInstance
- Controller
- ReflectionMetadataCallbacks
- ReflectionMetadataFunctions
- ReflectionMetadataYieldFunctions
- ReflectionMetadataProperties
- ReflectionMetadata
- AdvancedDragger
- HapticService
- FriendService
- GamepadService
No Result Found !!!
AccelerometerEnabled
This property can only be read from. Attempting to write to it will cause an error.
This item is not replicated across Roblox’s server/client boundary.
This property describes whether the the user’s device has an accelerometer
An accelerometer is a component found in most mobile devices that measures acceleration (change in speed).
For example, the following code snippet demonstrates how to check if the user’s device has an accelerometer.
local userInputService = game:GetService("UserInputService")
local accelerometerEnabled = oserInputService.AccelerometerEnabled
if accelerometerEnabled then
print("Accelerometer enabled!")
else
print("Accelerometer not enabled!")
end
If the device has an enabled accelerometer, you can get it’s current acceleration by using the UserInputService/GetDeviceAcceleration function or track when the device’s acceleration changes by using the UserInputService/DeviceAccelerationChanged event.
As UserInputService is client-side only, this property can only be used in a LocalScript.
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.
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:wait()
local head = character:WaitForChild("Head")
local camera = game.Workspace.CurrentCamera
local currentRotation = camera.CFrame-- CFrame.new(Vector3.new(0,0,0), Vector3.new(0,0,0))
local lastInputFrame = nil
local upsideDown = false
wait()
local orientationSet = false
local function GravityChanged(gravity)
if not orientationSet then
upsideDown = (gravity.Position.X < -.5 or gravity.Position.Z > .5)
orientationSet = true
end
end
local function RotationChanged(rotation, rotCFrame)
if orientationSet then
if not lastInputFrame then
lastInputFrame = rotCFrame
end
local delta = rotCFrame * lastInputFrame:inverse()
local x,y,z = delta:toEulerAnglesXYZ()
if upsideDown then
delta = CFrame.Angles(-x, y, z)
else
delta = CFrame.Angles(x, -y, z)
end
currentRotation = currentRotation * delta
lastInputFrame = rotCFrame
end
end
local function HideCharacter()
for _, limb in pairs (character:GetChildren()) do
if limb:IsA("Part") then
limb.Transparency = 1
end
end
end
local function UpdateCamera()
local camera = game.Workspace.CurrentCamera
camera.CoordinateFrame = currentRotation
camera.Focus = CFrame.new(currentRotation * Vector3.new(0,0,-10))
end
if UserInputService.GyroscopeEnabled then
UserInputService.DeviceGravityChanged:Connect(GravityChanged)
UserInputService.DeviceRotationChanged:Connect(RotationChanged)
HideCharacter()
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function()
camera.CFrame = CFrame.new(head.Position - Vector3.new(0,8,10)) * currentRotation
camera.Focus = CFrame.new(currentRotation * Vector3.new(0,0,-10))
end)
end
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.
local UserInputService = game:GetService("UserInputService")
local Ball = game.Workspace.Ball
local RealGravity = Instance.new("BodyForce", Ball)
local AntiGravity = Instance.new("BodyForce", Ball)
AntiGravity.force = Vector3.new(0, 196.2 * Ball:GetMass(), 0)
local function MoveBall(gravity)
RealGravity.force = gravity.Position * 196.2 * game.Workspace.Ball:GetMass()
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceGravityChanged:Connect(MoveBall)
end
How this site use cookies
This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on this Platform, please refer to our Privacy and Cookie Policy.