VRService

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Non costruibile
Assistenza

VRService è responsabile della gestione delle interazioni tra Roblox e Virtual Reality (VR). I suoi metodi, proprietà e eventi ti aiutano a fornire la migliore esperienza per gli utenti finali che cercano di sperimentare Roblox su dispositivi VR.

Vedi Linee guida VR per ulteriori informazioni sulla pubblicazione di un'esperienza per dispositivi VR.

Campioni di codice

The following example demonstrates how to get the Enum.UserCFrame of the left controller and place a part at that point in real world space. The CFrame of the controller changes whenever the device moves, so you should update the necessary parts whenever VRService.UserCFrameChanged fires.

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

Sommario

Proprietà

Metodi

Proprietà

AutomaticScaling

Lettura Parallela

Quando impostato su Enum.VRScaling.World, Camera.HeadScale regola l'aggiustamento in modo che lo scala del mondo sia visto dalla prospettiva dell'Avatar. Un giocatore con un piccolo avatar percepirà gli oggetti intorno a loro come più grandi di un giocatore con un grande avatar.

AvatarGestures

Lettura Parallela

Quando impostato su true, un giocatore VR sarà in grado di animare le sue mani e la sua testa usando i suoi controller e headset.

Questa proprietà deve essere impostata sul Server.

Lettura Parallela

FadeOutViewOnCollision

Lettura Parallela

Quando è vero, la vista di un GiocatoreVR svanisce quando la loro testa si scontra con un oggetto. Questa proprietà impedisce ai giocatori di essere in grado di vedere attraverso i muri mentre in VR. Il valore predefinito è vero.

GuiInputUserCFrame

Non Replicato
Lettura Parallela

Questa proprietà descrive ciò che Enum.UserCFrame è responsabile per l'input in VR. Ad esempio, se un set di cuffie VR è responsabile, il valore di questa proprietà sarà Enum.UserCFrame.Head .

Per verificare se Roblox rileva eventuali dispositivi VR, che sarebbero responsabili dell'input in VR, puoi controllare la ProprietàVREnabled.

Campioni di codice

This example checks if Roblox detects a VR device. If a VR device is detected, this prints the name of the UserCFrame responsible for VR input. If not, this example prints "No VR device detected!".

VRService.GuiInputUserCFrame

local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("No VR device detected!")
end
Lettura Parallela

ThirdPersonFollowCamEnabled

Sola Lettura
Non Replicato
Lettura Parallela

VREnabled

Sola Lettura
Non Replicato
Lettura Parallela

Questa proprietà descrive se l'utente sta usando un Dispositivodi realtà virtuale (VR).

Se un dispositivo VR è abilitato, puoi interagire con la sua posizione e la sua posizione attraverso metodi come UserInputService:GetUserCFrame() . Puoi anche reagire alla sua posizione con l'evento UserInputService.UserCFrameChanged .


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

Questa proprietà può essere utilizzata solo in un LocalScript .

Vedi anche

Campioni di codice

This example demonstrates how to implement a head tracking script that mirrors the movement of a virtual reality (VR) headset (the user's actual head) to their in-game character's head.

The example first check if the user is using a VR device by checking the value of the VREnabled() property. This example only works if the user is using a VR headset.

To determine the initial CFrame of the character's head, the code sample calls GetUserCFrame() and passes Enum.UserCFrame.Head as the argument.

To update the head's CFrame whenever the user's VR headset moves, the example connects the VRService.UserCFrameChanged event to the TrackHead() function. When the event fires to indicate that a VR device moved, TrackHead() checks if the headset moved. If the headset moved, the function updates the CFrame of the character's head to the CFrame value provided as an argument.

As the UserCFrame enum also tracks VR left and right hand devices, the concept of VR device tracking can be expanded to other character bodyparts.

In order for the example to work as expected, it must be placed in a LocalScript.

VR Head Tracking

local VRService = game:GetService("VRService")
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 VRService.VREnabled then
-- Set the initial CFrame
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- Track VR headset movement and mirror for character's head
VRService.UserCFrameChanged:Connect(TrackHead)
end

Metodi

GetTouchpadMode

Questo metodo restituisce il Enum.VRTouchpadMode che indica il modo di un Enum.VRTouchpad specificato. Il modo restituito indica come l'Giocointeragisce con il loro touchpad per giocare.

Questo può essere utilizzato anche insieme ai diversi metodi e eventi VR UserInputService.

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .

Parametri

Il VRTouchpad specificato.


Restituzioni

Il modo del VRTouchpad specificato.

Campioni di codice

This example retrieves and prints the name of the user's current VRTouchpad.Left touchpad mode.

VRService:GetTouchpadMode

local VRService = game:GetService("VRService")
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)

GetUserCFrame

Questo metodo restituisce un CFrame che descrive la posizione e l'orientamento di un dispositivo di realtà virtuale specificato come un offset dal punto di un mondo Spazio. Questo metodo dovrebbe essere utilizzato quando si implementa la compatibilità VR in un gioco per ottenere e tracciare il movimento di un DispositivoVR connesso.

Usando il metodo, gli sviluppatori possono implementare funzionalità come la riposizione del personaggio in gioco corrispondente alla posizione di un DispositivoVR connesso. Questo può essere fatto modificando il CFrame del personaggio in gioco per corrispondere alla posizione del dispositivo VR specificato usando gli argumenti value e CFrame passati dall'evento.

VRService fornisce anche un evento UserCFrameChanged che si attiva automaticamente quando il CFrame di un dispositivo VR connesso cambia, a patto che venga utilizzato in un 0> Class.LocalScript0> .

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .

Parametri

Il specifico UserCFrame .


Restituzioni

Campioni di codice

This example positions a part at the player's left hand, assuming Camera.HeadLocked = true

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

Questo metodo restituisce vero se il dispositivo di realtà virtuale specificato Enum.UserCFrame è disponibile per essere ascoltato. Può essere utilizzato per determinare se un DispositivoVR specificato, come Enum.UserCFrame.Head , è connesso al Giocodell'utente.

Questo può essere utilizzato anche insieme ai diversi metodi e eventi VR UserInputService.

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .

Parametri

Il tipo specificato di DispositivoVR.


Restituzioni

Un bool che indica se il dispositivo VR specificato è abilitato ( true ) o disabilitato ( false ).

Campioni di codice

This example indicates whether the UserCFrame.Head VR device is enabled or disabled for the user. If the device is enabled, this prints "VR device is enabled!". If the device is disabled, this prints "VR device is disabled!".

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

Questo metodo riposiziona il CFrame dell'utente nella posizione attuale della VR Headset indossata dall'utente. Può essere utilizzato per assicurare che la testa dell'utente in gioco sia posizionata secondo la posizione della VR Headset dell'utente.

Questo si comporta identificativamente a UserInputService:RecenterUserHeadCFrame() .

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .


Restituzioni

void

Campioni di codice

This example fires the function to recenter the CFrame of the user's head to the current location of the VR headset being worn by the user.

VRService:RecenterUserHeadCFrame

local VRService = game:GetService("VRService")
VRService:RecenterUserHeadCFrame()

RequestNavigation

void

Questo metodo richiede la navigazione all'CFrame specificato utilizzando il metodo specificato Enum.UserCFrame come punto di origine per la parabola del visualizzatore. Può essere utilizzato per incorporare la realtà virtuale (VR) nel tuo gioco fornendo un modo per visualizzare un percorso di navigazione dall'Datatype.CFrame dell'utente a una destinazione.

VRService ha un evento simile, NavigationRequested, usato per rilevare tali richieste. Questo può essere utilizzato anche insieme ai diversi metodi e eventi VR di Class.UserInputService.

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .

Parametri

cframe: CFrame

Le coordinate specificate CFrame .

inputUserCFrame: Enum.UserCFrame

Il dispositivo VR per cui la navigazione è richiesta.


Restituzioni

void

Campioni di codice

This example requests navigation from the user's UserCFrame.Head coordinates to the CFrame coordinates of a Part named NavigationDestination.

Note: In order for this to work, a Part named NavigationDestination must exist in the game's Workspace.

VRService:RequestNavigation

local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)

SetTouchpadMode

void

Questo metodo imposta il modo in cui il Enum.VRTouchpad specificato si trova sul Enum.VRTouchpadMode specificato. Può essere utilizzato per modificare il modo in cui l'utente interagisce con il En册.VRTouchpad touchpad in modo da consentire all'utente di interagire con il gioco in modo diverso utilizzando il touchpad.

Questo può essere utilizzato anche insieme ai diversi metodi e eventi VR UserInputService.

Questo metodo funzionerà solo quando viene utilizzato in un LocalScript .

Parametri

Il enum.VRTouchpad|VRTouchpad specificato che vuoi impostare la modalità.

Il modo in cui vuoi impostare il VRTouchpad specificato.


Restituzioni

void

Campioni di codice

This example sets the user's VRTouchpad.Left touchpad mode to TouchMode.Touch. This means that the left touchpad is treated as ButtonB.

VRService:SetTouchpadMode

local VRService = game:GetService("VRService")
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)

Eventi

Questo evento si attiva quando la navigazione è richiesta da VRService per un VR Dispositivospecificato. Si attiva con una coordinata Enum.UserCFrame e la specifica CFrame che indica il dispositivo che richiede la navigazione.

Questo evento può essere utilizzato insieme agli eventi e ai metodi di servizio UserInputService.

Poiché questo evento si attiva localmente, può essere utilizzato solo in un LocalScript .

Parametri

cframe: CFrame

Le richieste CFrame coordinate.

inputUserCFrame: Enum.UserCFrame

Indica il dispositivo VR per cui la navigazione è richiesta.


Campioni di codice

This example prints the name of the UserCFrame VR device making the request, and the CFrame coordinates passed.

VRService.NavigationRequested

local VRService = game:GetService("VRService")
VRService.TouchpadModeChanged:Connect(function(cframe, inputUserCFrame)
print(inputUserCFrame.Name .. " made request with CFrame: " .. cframe)
end)

TouchpadModeChanged

Questo evento si attiva se il Enum.VRTouchpadMode di un Enum.VRTouchpad viene cambiato. Puoi utilizzare questo evento per tracciare gli stati dei touchpad VR connessi tramite il client dell'utente.

Questo evento può essere utilizzato insieme agli eventi e ai metodi di servizio UserInputService.

Poiché questo evento si attiva localmente, può essere utilizzato solo in un LocalScript .

Parametri

Il touchpad che ha cambiato modalità.

Il nuovo modo.


Campioni di codice

This example fires when the state of a VRTouchpad changes. It prints the name of the Touchpad that changed, and the state that it changed to.

VRService.TouchpadModeChanged

local VRService = game:GetService("VRService")
VRService.NavigationRequested:Connect(function(pad, mode)
print(pad.Name .. " Touchpad changed to state: " .. mode.Name)
end)

UserCFrameChanged

Questo evento si attiva quando un Enum.UserCFrame è cambiato, ad esempio quando l'utente sposta un DispositivoVR connesso. Può essere utilizzato insieme a GetUserCFrame() per tracciare le posizioni CFrame di un Dispositivo

Poiché questo evento si attiva localmente, può essere utilizzato solo in un LocalScript .

Parametri

Il tipo di dispositivo VR che è cambiato.

value: CFrame

I coordinatori aggiornati CFrame del dispositivo VR dopo la modifica.


Campioni di codice

This event fires when the user moves a connected VR device. When the event fires, this prints the name of the VR device type that changed, and the updated CFrame coordinates.

VRService.UserCFrameChanged

local VRService = game:GetService("VRService")
VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
print(userCFrameType.Name .. " changed. Updated Frame: " .. tostring(cframeValue))
end)

UserCFrameEnabled

Questo evento si attiva quando un Enum.UserCFrame è abilitato o disabilitato. Può essere utilizzato insieme a GetUserCFrameEnabled() per tracciare se un UserCFrame specificato è abilitato o camb

Poiché questo evento si attiva localmente, può essere utilizzato solo in un LocalScript .

Parametri

Il UserCFrame che si attiva o si disattiva.

enabled: bool

Un bool che indica se UserCFrame è abilitato ( true ) o disabilitato ( false ).


Campioni di codice

This example fires when a UserCFrame changes state, printing the name of the changed UserCFrame and whether it changed got enabled or disabled.

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)