VRService

非推奨を表示

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

作成できません
サービス

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

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

並列読み取り

Enum.VRScaling.World に設定すると、Camera.HeadScale は世界のスケールがアバターの視点から見えるように調整します。小さなアバターを持つプレイヤーは、大きなアバターを持つプレイヤーよりも、周囲のオブジェクトを大きく感じるでしょう。

AvatarGestures

並列読み取り

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

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

並列読み取り

FadeOutViewOnCollision

並列読み取り

真になると、VR プレイヤーのビューは頭がオブジェクトに衝突すると黒に消えます。このプロパティは、プレイヤーが VR 中に壁を通して見ることができないようにします。デフォルト値は true です。

GuiInputUserCFrame

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

このプロパティは、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 でのみ使用できます。

参照してください: See Also

コードサンプル

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.VRTouchpad のモードを示す Enum.VRTouchpadMode を返します。返されたモードは、ユーザーがタッチパッドとどのように対話してゲームをプレイするかを示します。

これは、複数の 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

このメソッドは、特定のバーチャルリアリティ (VR) デバイスの位置と方向を実世界空間からオフセットとして記述する CFrame を返します。このメソッドは、VR の互換性をゲームに実装して、接続された VR デバイスの動作を取得し、追跡するときに使用する必要があります。

メソッドを使用すると、開発者は、接続された VR デバイスの場所に対応するユーザーのゲーム内キャラクターの再配置などの機能を実装できます。これは、ユーザーのゲーム内キャラクターの CFrame を変更して、ユーザーCFrame枚数と CFrame 値引数を使用して指定された VR デバイスの CFrame にマッチさせることで行うことができます。

は、接続された VR デバイスの が変更されると自動的に発動するイベントを提供しますが、それは で使用されている限りです。

このメソッドは 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) が聴くことができる場合、真を返します。特定の VR デバイス、例えば Enum.UserCFrame.Head が、ユーザーのゲームに接続されているかどうかを判断するのに使用できます。

これは、複数の 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 デバイス。

既定値: ""

戻り値

()

コードサンプル

この例では、ユーザーの UserCFrame.Head 座標から Part という名前の CFrame の座標へのナビゲーションをリクエストする。

注: これが機能するには、ゲームのワークスペースに ナビゲーション目的地 という名前のパーツが存在する必要があります。

VRService:リクエスト航行

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)

イベント

このイベントは、指定された VR デバイスからナビゲーションがリクエストされたときに発動します。それは CFrame 座標で発射し、指定された Enum.UserCFrame がナビゲーションをリクエストするデバイスを示します。

このイベントは、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 が変更されたときに発動します。It can be used alongside GetUserCFrame() を使用して、VR デバイスの CFrame 座標を追跡し、変更/移動するとき。また、UserInputService サービスイベントやメソッドと一緒に使用することもできます。

このイベントはローカルで発動するため、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 が有効になっているか、その状態が変更されたときを追跡することができます。また、UserInputService サービスイベントやメソッドと一緒に使用することもできます。

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

パラメータ

UserCFrame が有効化されたり無効化されたりしています。

enabled: boolean

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)