VRService

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
サービス

VRService は、Roblox とバーチャルリアリティ (VR) の間のインタラクションを処理する責任があります。そのメソッド、プロパティ、イベントは、最高のエクスペリエンスを提供するために、エンドユーザーが Roblox を VR デバイスで経験しようとしています。

VR デバイス用のエクスペリエンスの公開については、VR ガイドライン を参照してください。

コードサンプル

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

概要

プロパティ

方法

イベント

プロパティ

AutomaticScaling

並列読み取り

Class.Camera.HeadScale を Camera.HeadScale に設定すると、Class.Camera.HeadScale は、アバターの視点から世界のスケールを調整します。小さなアバターを持つプレイヤーは、周りのオブジェクトを大きなアバターを持つプレイヤーよりも大きなサイズで見ることがあります。

AvatarGestures

並列読み取り

設定を「真」にすると、VR プレイヤーはコントローラーとヘッドセットを使用して手と頭をアニメートできるようになります。

このプロパティは、サーバーに設定する必要があります。

並列読み取り

FadeOutViewOnCollision

並列読み取り

[VR] プレイヤーのビューは、頭がオブジェクトに当たると黒に濃くなります。これは、プレイヤーが VR で壁を見ることができないようにします。デフォルトの値は true です。

GuiInputUserCFrame

複製されていません
並列読み取り

このプロパティは、VR の入力に責任を持つ Enum.UserCFrame です。たとえば、VR ヘッドセットが責任を持っている場インスタンス、このプロパティの値は Enum.UserCFrame.Head になります。

Roblox が VR デバイスを検出するかどうかを確認するには、VREnabled プロパティをチェックできます。

コードサンプル

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
並列読み取り

ThirdPersonFollowCamEnabled

読み取り専用
複製されていません
並列読み取り

VREnabled

読み取り専用
複製されていません
並列読み取り

このプロパティは、ユーザーがバーチャルリアリティ (VR) デバイスを使用しているかどうかを記述します。

VR デバイスが有効になっている場合は、UserInputService:GetUserCFrame() などのメソッドを使用して、その場所と移動をインタラクトできます。また、UserInputService.UserCFrameChanged イベントを使用して、VR デバイスの移動に反応することもできます。


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

このプロパティは LocalScript 内のみで使用できます。

参照してください

コードサンプル

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

方法

GetTouchpadMode

このメソッドは、 Enum.VRTouchpadMode を返し、指定された Enum.VRTouchpad のモードを示しています。返されたモードは、ユーザーがタッチパッドにどのようにインタラクトするかを示しています。

これは、さまざまな UserInputService VR メソッドとイベントと一緒に使用できます。

このメソッドは LocalScript 内でのみ使用できます。

パラメータ

指定された VRTouchpad


戻り値

指定された VRTouchpad のモード。

コードサンプル

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

このメソッドは、CFrame を返します。これは、特定のバーチャルリアリティ (VR) デバイスの位置と方向を実世界スペースのオフセットで表現します。このメソッドは、ゲームに VR のコンパビリティを実装する際に使用する必要があります。これは、接続された VR デバイスの移動を追跡するためにゲーム内の VR コ

メソッドを使用すると、ユーザーのインゲームキャラクターを、接続された VR デバイスの場所に対応させるなど、機能の再設定を実装できます。これは、ユーザーのインゲームキャラクターの CFrame を変更して、ユーザーCFrame の CFrame 値アルガートを

VRService また、UserCFrameChanged イベントを提供します。これは、接続された VR デバイスの CFrame が変更されると自動的に発動するので、0> Class.LocalScript0> で使用されています。

このメソッドは LocalScript 内でのみ使用できます。

パラメータ

指定された UserCFrame


戻り値

コードサンプル

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

このメソッドは、指定の Enum.UserCFrame バーチャルリアリティデバイス (VR) が聞き取り可能であるかどうかにより、Enum.UserCFrame.Head などの指定のバーチャルリアリティデバイス (VR) が接続されているかどうかを判断できます。これを使用して、特定の VR デバイス、例えば enum.UserCFrame.

これは、さまざまな UserInputService VR メソッドとイベントと一緒に使用できます。

このメソッドは LocalScript 内でのみ使用できます。

パラメータ

指定された VR デバイスの種類。


戻り値

指定された VR デバイスが有効 ( true ) または無効 ( false ) です。

コードサンプル

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

()

このメソッドは、CFrame のユーザーの頭を現在の VR ヘッドセットの位置に再センターします。これは、ユーザーのゲーム内頭がユーザーの VR ヘッドセットの位置に基づいて配置されることを確認するために使用できます。

これは UserInputService:RecenterUserHeadCFrame() と同じように動作します。

このメソッドは LocalScript 内でのみ使用できます。


戻り値

()

コードサンプル

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

()

このメソッドは、指定の CFrame にネビゲーションをリクエストし、指定の Enum.UserCFrame をオリジンとして、ビジュアライザーパラボラを視覚化するために使用します。これを使用すると、ゲームにバーチャルリアリティ (VR) を統合できます。ユーザーの VR デバイスから目

VRService には、類似するイベント、NavigationRequested、が使用されています。これは、これらのリクエストを検出するために使用されます。これは、UserInputService VRメソッドとイベントのいくつかと一緒に使用できます。

このメソッドは LocalScript 内でのみ使用できます。

パラメータ

cframe: CFrame

指定された CFrame 座標。

inputUserCFrame: Enum.UserCFrame

ナビゲーションをリクエストされた VR デバイス。


戻り値

()

コードサンプル

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

()

このメソッドは、指定された Enum.VRTouchpad のモードを指定された Enum.VRTouchpadMode に設定します。これを使用すると、ユーザーのバーチャルリアリティ (VR) タッチパッドモードを変更して、タッチパッドを使用してゲームとユーザーが異なってインタラクトできます。

これは、さまざまな UserInputService VR メソッドとイベントと一緒に使用できます。

このメソッドは LocalScript 内でのみ使用できます。

パラメータ

指定された VRTouchpad を設定しています。

指定した VRTouchpad に設定したいモード。


戻り値

()

コードサンプル

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)

イベント

このイベントは、VRService から指定された Enum.UserCFrame VR デバイスのためにナビゲーションをリクエストすると発動します。ナビゲーションをリクエストするのは、CFrame コーディネートで、指定された 1> Class.UserCFrame1> がデバ

このイベントは UserInputService サービスのイベントとメソッドと一緒に使用できます。

このイベントはローカルで発生するため、 LocalScript 内のみで使用できます。

パラメータ

cframe: CFrame

リクエストされた CFrame 座標。

inputUserCFrame: Enum.UserCFrame

ナビゲーションがリクエストされている VR デバイスを指します。


コードサンプル

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

このイベントは、Enum.VRTouchpadModeEnum.VRTouchpad が変更された場合に発生します。このイベントを使用して、ユーザーのクライアントを介して接続された VR タッチパッドの状態を追跡できます。

このイベントは UserInputService サービスのイベントとメソッドと一緒に使用できます。

このイベントはローカルで発生するため、 LocalScript 内のみで使用できます。

パラメータ

モードが変わったタッチパッド。

新しいモード。


コードサンプル

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

このイベントは、ユーザーが接続された VR デバイスを移動するなど、Enum.UserCFrame が変更されたときに発動します。GetUserCFrame() サービスイベントとメソッドを使用して、CFrame

このイベントはローカルで発生するため、 LocalScript 内のみで使用できます。

パラメータ

変更した VR デバイスのタイプ。

value: CFrame

変更後の VR デバイスの更新された CFrame コーディネート。


コードサンプル

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

このイベントは、Enum.UserCFrame が有効になったり無効になったりすると発動します。GetUserCFrameEnabled() の状態を追跡するために、UserCFrame サービスイベントとメ

このイベントはローカルで発生するため、 LocalScript 内のみで使用できます。

パラメータ

UserCFrame|UserCFrame を有効にするか無効にする。

enabled: boolean

UserCFrame|UserCFrame が有効 ( true ) または無効 ( false ) であるかを示すブールーン。


コードサンプル

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)