學習
引擎類別
VRService
無法建立
服務

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


範例程式碼
虛擬實境服務
'local VRService = game:GetService("VRService")
local part = workspace.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- 考慮頭部縮放
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale
part.CFrame = workspace.CurrentCamera.CFrame * handOffset'

API 參考
屬性
AutomaticScaling
平行讀取
功能: Input
VRService.AutomaticScaling:Enum.VRScaling

AvatarGestures
平行讀取
功能: Input
VRService.AvatarGestures:boolean

ControllerModels
平行讀取
功能: Input
VRService.ControllerModels:Enum.VRControllerModelMode

FadeOutViewOnCollision
平行讀取
功能: Input
VRService.FadeOutViewOnCollision:boolean

GuiInputUserCFrame
未複製
平行讀取
功能: Input
VRService.GuiInputUserCFrame:Enum.UserCFrame
範例程式碼
VRService.GuiInputUserCFrame
local VRService = game:GetService("VRService")
if VRService.VREnabled\ then
print(VRService.GuiInputUserCFrame.Name)
else
print("未偵測到 VR 裝置!")
end

LaserPointer
平行讀取
功能: Input
VRService.LaserPointer:Enum.VRLaserPointerMode

ThirdPersonFollowCamEnabled
唯讀
未複製
平行讀取
功能: Input
VRService.ThirdPersonFollowCamEnabled:boolean

VREnabled
唯讀
未複製
平行讀取
功能: Input
VRService.VREnabled:boolean
範例程式碼
虛擬實境頭部追蹤
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
-- 設定初始 CFrame
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- 追蹤 VR 頭盔移動並鏡像角色的頭部
VRService.UserCFrameChanged:Connect(TrackHead)
end

方法
GetTouchpadMode
功能: Input
VRService:GetTouchpadMode(pad:Enum.VRTouchpad):Enum.VRTouchpadMode
參數
範例程式碼
VRService:獲取觸控板模式
-- 本地變量 VRService 是遊戲中的 VRService 服務
local VRService = game:GetService("VRService")
-- 獲取左側觸控板的模式
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)

GetUserCFrame
功能: Input
VRService:GetUserCFrame(type:Enum.UserCFrame):CFrame
參數
返回
範例程式碼
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)
-- 考慮頭部縮放
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffset

GetUserCFrameEnabled
功能: Input
VRService:GetUserCFrameEnabled(type:Enum.UserCFrame):boolean
參數
返回
範例程式碼
VRService:獲取用戶CFrame啟用狀態
local VRService = game:GetService("VRService")
local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
if isEnabled then
print("VR 設備已啟用!")
else
print("VR 設備已禁用!")
end

RecenterUserHeadCFrame
功能: Input
VRService:RecenterUserHeadCFrame():()
返回
()
範例程式碼
VRService:重新中心使用者頭部CFrame
local VRService = game:GetService("VRService")
-- 觸發函式以重新中心使用者的頭部CFrame
VRService:RecenterUserHeadCFrame()

RequestNavigation
功能: Input
VRService:RequestNavigation(
cframe:CFrame, inputUserCFrame:Enum.UserCFrame
):()
參數
cframe:CFrame
inputUserCFrame:Enum.UserCFrame
返回
()
範例程式碼
VRService:RequestNavigation
-- 定義 VRService
local VRService = game:GetService("VRService")
-- 尋找目的地
local destination = workspace:FindFirstChild("NavigationDestination")
-- 請求導航
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)

SetTouchpadMode
功能: Input
VRService:SetTouchpadMode(
):()
返回
()
範例程式碼
VRService:設定觸控板模式
local VRService = game:GetService("VRService")
-- 設置左側觸控板模式為觸摸模式
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)

活動
NavigationRequested
功能: Input
VRService.NavigationRequested(
cframe:CFrame, inputUserCFrame:Enum.UserCFrame
參數
cframe:CFrame
inputUserCFrame:Enum.UserCFrame
範例程式碼
VRService.NavigationRequested
local VRService = game:GetService("VRService")
VRService.NavigationRequested:Connect(function(cframe, inputUserCFrame)
print(inputUserCFrame.Name .. " 以 CFrame 發出請求: " .. cframe)
end)

TouchpadModeChanged
功能: Input
VRService.TouchpadModeChanged(
範例程式碼
VRService.TouchpadModeChanged
local VRService = game:GetService("VRService")
VRService.TouchpadModeChanged:Connect(function(pad, mode)
print(pad.Name .. " 觸控板狀態變更為: " .. mode.Name)
end)

UserCFrameChanged
功能: Input
VRService.UserCFrameChanged(
參數
value:CFrame
範例程式碼
VRService.UserCFrameChanged
local VRService = game:GetService("VRService")
VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
print(userCFrameType.Name .. " 改變了。更新的框架: " .. tostring(cframeValue))
end)

UserCFrameEnabled
功能: Input
VRService.UserCFrameEnabled(
type:Enum.UserCFrame, enabled:boolean
參數
enabled:boolean
範例程式碼
VRService.UserCFrameEnabled
-- 當 UserCFrame 狀態改變時的連接
local VRService = game:GetService("VRService")
VRService.UserCFrameEnabled:Connect(function(type,
enabled)
if enabled then
print(type.Name .. " 被啟用了!")
else
print(type.Name .. " 被禁用了!")
end
end)

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。