GSmGpE6CwX2y9JjB25B8
We use cookies on this site to enhance your user experience

Device Orientation

Device Orientation

Aug 29 2019, 9:14 AM PST 5 min

On phones and tablets, the device orientation can have a profound impact on gameplay. For example, landscape mode is best operated with two thumbs while portrait mode may lend itself to one-finger gameplay.

By default, Roblox games run in landscape mode, allowing the game to switch between landscape “left” and landscape “right” as the player’s device rotates. However, games can be locked to a particular orientation if desired.

Orientation Modes

There are five different orientation modes, including two sensor modes and three locked modes.

Sensor Modes
Landscape Sensor The default Roblox setting in which the game will always appear in landscape mode (no portrait mode) and the device will detect its physical orientation to ensure the game view is always oriented upward.
Sensor The device will detect its physical orientation to ensure the game view is always oriented upward, switching between landscape and portrait mode as needed.
Locked Modes
Landscape Left On devices with a physical home button, it will be to the left of the display. On devices with a virtual home/nav bar, its touch region will be at the bottom of the display.
Landscape Right On devices with a physical home button, it will be to the right of the display. On devices with a virtual home/nav bar, its touch region will be at the bottom of the display.
Portrait On devices with a physical home button, it will be below the display. On devices with a virtual home/nav bar, its touch region will be at the bottom of the display.

Orientation Properties

There are three ways to work with device orientation:

Starting Orientation

StarterGui/ScreenOrientation sets the default orientation for a place. Acceptable values include:

  • enum/ScreenOrientation|Enum.ScreenOrientation.LandscapeSensor
  • enum/ScreenOrientation|Enum.ScreenOrientation.Sensor
  • enum/ScreenOrientation|Enum.ScreenOrientation.LandscapeLeft
  • enum/ScreenOrientation|Enum.ScreenOrientation.LandscapeRight
  • enum/ScreenOrientation|Enum.ScreenOrientation.Portrait

Because this property affects all new players who join the game, you can simply set its value in StarterGuiScreenOrientation within Studio.

In-Game Orientation

PlayerGui/ScreenOrientation explicitly changes the game’s orientation for a player. When this property is set to one of the enum/ScreenOrientation|ScreenOrientation enums in a LocalScript, the game will immediately orient itself to match the setting. This can be useful when a game needs to provide a particular experience like locking the view to portrait for a minigame.

local Players = game:GetService("Players")
local playerGUI = Players.LocalPlayer:WaitForChild("PlayerGui")

wait(2)

playerGUI.ScreenOrientation = Enum.ScreenOrientation.Portrait

Current Orientation

PlayerGui/CurrentScreenOrientation gets the current device orientation. Possible values include:

  • enum/ScreenOrientation|Enum.ScreenOrientation.LandscapeLeft
  • enum/ScreenOrientation|Enum.ScreenOrientation.LandscapeRight
  • enum/ScreenOrientation|Enum.ScreenOrientation.Portrait
local Players = game:GetService("Players")
local playerGUI = Players.LocalPlayer:WaitForChild("PlayerGui")

print(playerGUI.CurrentScreenOrientation)
Tags:
  • mobile
  • orientation
  • landscape
  • portrait