Show Deprecated
Not Creatable Service
VRService is responsible for handling interactions between Roblox andVirtual Reality (VR). Its methods, properties, and events help you provide thebest experience for end users seeking to experience Roblox on VR devices.
See VR Guidelines for moreinformation on publishing an experience for VR devices.
Code Samples
VRService
local VRService = game:GetService("VRService")
local part = workspace.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale
part.CFrame = workspace.CurrentCamera.CFrame * handOffset
Summary
Properties
AutomaticScaling:Enum.VRScaling
Read Parallel
Automatically adjusts scaling in VR to align the player with their avatar.
AvatarGestures:bool
Read Parallel
When true, a VR player will be able to animate their hands and head usingtheir controllers and headset.
FadeOutViewOnCollision:bool
Read Parallel
When true, a VR player's view will fade to black when their head collideswith an object.
GuiInputUserCFrame:Enum.UserCFrame
Not Replicated
Read Parallel
Describes what Enum.UserCFrame is responsible for input in VR.
ThirdPersonFollowCamEnabled:bool
Read Only
Not Replicated
Read Parallel
VREnabled:bool
Read Only
Not Replicated
Read Parallel
Describes whether the user is using a virtual reality device.
View all inherited from Instance
Methods
GetTouchpadMode(pad : Enum.VRTouchpad):Enum.VRTouchpadMode
Returns the VRTouchpadMode indicating the mode of a specified VRTouchpad.
GetUserCFrame(type : Enum.UserCFrame):CFrame
Returns a CFrame describing the position & orientation of a specifiedvirtual reality device as an offset from a point in real world space.
GetUserCFrameEnabled(type : Enum.UserCFrame):bool
Returns true if the specified Enum.UserCFrame is available to belistened to.
RecenterUserHeadCFrame():void
Re-centers the CFrame to the current location of the VR headsetbeing worn by the user.
RequestNavigation(cframe : CFrame,inputUserCFrame : Enum.UserCFrame):void
Requests navigation to the specified CFrame using the specifiedEnum.UserCFrame as the origin for the visualizer parabola.
SetTouchpadMode(pad : Enum.VRTouchpad,mode : Enum.VRTouchpadMode):void
Sets the mode of the specified Enum.VRTouchpad to the specifiedEnum.VRTouchpadMode.
View all inherited from Instance
Events
NavigationRequested(cframe : CFrame,inputUserCFrame : Enum.UserCFrame):RBXScriptSignal
Fired when navigation is requested from VRService.
TouchpadModeChanged(pad : Enum.VRTouchpad,mode : Enum.VRTouchpadMode):RBXScriptSignal
Fires if the Enum.VRTouchpadMode of a Enum.VRTouchpad is changed.
UserCFrameChanged(type : Enum.UserCFrame,value : CFrame):RBXScriptSignal
Fires when a Enum.UserCFrame is changed.
UserCFrameEnabled(type : Enum.UserCFrame,enabled : bool):RBXScriptSignal
Fires when a Enum.UserCFrame is enabled or disabled.
View all inherited from Instance
Properties
AutomaticScaling
Enum.VRScaling
Read Parallel
When set to Enum.VRScaling.World, Camera.HeadScale adjusts sothat the scale of the world is seen from the avatar's perspective. Aplayer with a small avatar will perceive the objects around them as largerthan a player with a large avatar will.
AvatarGestures
bool
Read Parallel
When set to true, a VR player will be able to animate their hands and headusing their controllers and headset.
This property must be set on the server.
FadeOutViewOnCollision
bool
Read Parallel
When true, a VR player's view fades to black when their head collides withan object. This property prevents players from being able to see throughwalls while in VR. The default value is true.
GuiInputUserCFrame
Enum.UserCFrame
Not Replicated Read Parallel
This property describes what Enum.UserCFrame is responsible for input inVR. For instance, if a VR headset is responsible, the value of thisproperty will be Enum.UserCFrame.Head.
To check if Roblox detects any VR devices, which would be responsible forinput in VR, you can check the VREnabledproperty.
Code Samples
VRService.GuiInputUserCFrame
local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("No VR device detected!")
end
ThirdPersonFollowCamEnabled
bool
Read Only Not Replicated Read Parallel
VREnabled
bool
Read Only Not Replicated Read Parallel
This property describes whether the user is using a virtual reality (VR)device.
If a VR device is enabled, you can interact with its location and movementthrough methods such as UserInputService:GetUserCFrame(). You canalso react to VR device movement using theUserInputService.UserCFrameChanged event.
local UserInputService = game:GetService("UserInputService")
local isUsingVR = UserInputService.VREnabled
if isUsingVR then
print("User is using a VR headset!")
else
print("User is not using a VR headset!")
end
This property can only be used in a LocalScript.
See Also
Camera.HeadLocked
UserInputService:GetUserCFrame()
UserInputService.UserCFrameChanged
Code Samples
VR Head Tracking
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local function TrackHead(inputType, value)
if inputType == Enum.UserCFrame.Head then
head.CFrame = value
end
end
if UserInputService.VREnabled then
-- Set the inital CFrame
head.CFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head)
-- Track VR headset movement and mirror for character's head
UserInputService.UserCFrameChanged:Connect(TrackHead)
end
View all inherited from Instance
Methods
GetTouchpadMode
Enum.VRTouchpadMode
This method returns the Enum.VRTouchpadMode indicating the mode of aspecified Enum.VRTouchpad. The returned mode indicates how the userinteracts with their touchpad to play the game.
This can also be used alongside the several UserInputService VRmethods and events.
This method will only work when used in a LocalScript.
Parameters
pad: Enum.VRTouchpad
The specified VRTouchpad.
Returns
Enum.VRTouchpadMode
The mode of the specified VRTouchpad.
Code Samples
VRService:GetTouchpadMode
local VRService = game:GetService("VRService")
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)
GetUserCFrame
CFrame
This method returns a CFrame describing the position andorientation of a specified virtual reality (VR) device as an offset from apoint in real world space. This method should be used when implementing VRcompatibility into a game to obtain and track the movement of a connectedVR device.
By using the method, developers can implement features such asre-positioning the user's in-game character corresponding to the locationof a connected VR device. This can be done by changing the CFrame of theuser's in-game character to match the CFrame of the specified VR deviceusing the UserCFrame enum and CFrame value arguments passed by theevent.
VRService also provides aUserCFrameChanged event thatautomatically fires when the CFrame of connected VR devicechanges, so long it is used in a LocalScript.
This method will only work when used in a LocalScript.
Parameters
type: Enum.UserCFrame
The specified UserCFrame.
Returns
CFrame
Code Samples
VRService:GetUserCFrame
local Workspace = game:GetService("Workspace")
local VRService = game:GetService("VRService")
local camera = Workspace.CurrentCamera
local part = script.Parent.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffset
GetUserCFrameEnabled
bool
This method returns true if the specified Enum.UserCFrame virtualreality device (VR) is available to be listened to. It can be used todetermine whether a specified VR device, such as Enum.UserCFrame.Head,is connected to the user's game.
This can also be used alongside the several UserInputService VRmethods and events.
This method will only work when used in a LocalScript.
Parameters
type: Enum.UserCFrame
The specified type of VR device.
Returns
bool
A boolean indicating whether the specified VR device is enabled(true) or disabled (false).
Code Samples
VRService:GetUserCFrameEnabled
local VRService = game:GetService("VRService")
local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
if isEnabled then
print("VR device is enabled!")
else
print("VR device is disabled!")
end
RecenterUserHeadCFrame
void
This method re-centers the CFrame of the user's head to thecurrent location of the VR headset being worn by the user. It can be usedto ensure that the user's in-game head is positioned according to thelocation of the user's VR headset.
This behaves identically toUserInputService:RecenterUserHeadCFrame().
This method will only work when used in a LocalScript.
Returns
void
Code Samples
VRService:RecenterUserHeadCFrame
local VRService = game:GetService("VRService")
VRService:RecenterUserHeadCFrame()
RequestNavigation
void
This method requests navigation to the specified CFrame usingthe specified Enum.UserCFrame as the origin for the visualizer parabola.It can be used to incorporate virtual reality (VR) into your game byproviding a means to visualize a navigation path from the user's VR deviceto a destination.
VRService has a similar event,NavigationRequested, used to detectsuch requests. This can also be used alongside the severalUserInputService VR methods and events.
This method will only work when used in a LocalScript.
Parameters
cframe: CFrame
The specified CFrame coordinates.
inputUserCFrame: Enum.UserCFrame
The VR device for which the navigation is requested.
Returns
void
Code Samples
VRService:RequestNavigation
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)
SetTouchpadMode
void
This method sets the mode of the specified Enum.VRTouchpad to thespecified Enum.VRTouchpadMode. It can be used to change the user'svirtual reality (VR) touchpad mode so that the user interacts with thegame differently using the touchpad.
This can also be used alongside the several UserInputService VRmethods and events.
This method will only work when used in a LocalScript.
Parameters
pad: Enum.VRTouchpad
The specified VRTouchpad you want to set the modeof.
mode: Enum.VRTouchpadMode
The mode you want to set the specified VRTouchpadto.
Returns
void
Code Samples
VRService:SetTouchpadMode
local VRService = game:GetService("VRService")
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)
View all inherited from Instance
Events
NavigationRequested
This event fires when navigation is requested from VRService for aspecified Enum.UserCFrame VR device. It fires with a CFramecoordinate and the specified Enum.UserCFrame indicating the devicerequesting the navigation.
This event can be used alongside UserInputService service eventsand methods.
Since this event fires locally, it can only be used in aLocalScript.
Parameters
cframe: CFrame
The requested CFrame coordinates.
inputUserCFrame: Enum.UserCFrame
Indicates the VR device for which navigation is requested.
Code Samples
VRService.NavigationRequested
local VRService = game:GetService("VRService")
VRService.TouchpadModeChanged:Connect(function(cframe, inputUserCFrame)
print(inputUserCFrame.Name .. " made request with CFrame: " .. cframe)
end)
TouchpadModeChanged
This event fires if the Enum.VRTouchpadMode of a Enum.VRTouchpad ischanged. You can use this event to track the states of VR touchpadsconnected via the user's client.
This event can be used alongside UserInputService service eventsand methods.
Since this event fires locally, it can only be used in aLocalScript.
Parameters
pad: Enum.VRTouchpad
The touchpad that changed mode.
mode: Enum.VRTouchpadMode
The new mode.
Code Samples
VRService.TouchpadModeChanged
local VRService = game:GetService("VRService")
VRService.NavigationRequested:Connect(function(pad, mode)
print(pad.Name .. " Touchpad changed to state: " .. mode.Name)
end)
UserCFrameChanged
This event fires when a Enum.UserCFrame is changed, for instance whenthe user moves a connected VR device. It can be used alongsideGetUserCFrame() to track theCFrame coordinates of a VR device, and when it changes/moves.It can also be used alongside UserInputService service events andmethods.
Since this event fires locally, it can only be used in aLocalScript.
Parameters
type: Enum.UserCFrame
The type of VR device that changed.
value: CFrame
The updated CFrame coordinates of the VR device after thechange.
Code Samples
VRService.UserCFrameChanged
local VRService = game:GetService("VRService")
VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
print(userCFrameType.Name .. " changed. Updated Frame: " .. tostring(cframeValue))
end)
UserCFrameEnabled
This event fires when a Enum.UserCFrame is enabled or disabled. It canbe used alongsideGetUserCFrameEnabled() to trackwhether a specified UserCFrame is enabled, and when itsstate changes. It can also be used alongside UserInputServiceservice events and methods.
Since this event fires locally, it can only be used in aLocalScript.
Parameters
type: Enum.UserCFrame
The UserCFrame getting enabled or disabled.
enabled: bool
A boolean indicating whether the UserCFrame isenabled (true) or disabled (false).
Code Samples
VRService.UserCFrameEnabled
local VRService = game:GetService("VRService")
VRService.UserCFrameEnabled:Connect(function(type, enabled)
if enabled then
print(type.Name .. " got enabled!")
else
print(type.Name .. " got disabled!")
end
end)
View all inherited from Instance