VRService

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ไม่สามารถสร้าง
บริการ

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

สรุป

คุณสมบัติ

  • อ่านพร้อมๆ กัน

    ปรับขนาดใน VR อวาตาร์

  • อ่านพร้อมๆ กัน

    เมื่อถูกต้อง ผู้เล่น VR เฮดเซ็ท

  • อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    เมื่อถูกต้อง มุมมองของผู้เล่น VR จะจางไปเป็นสีดําเมื่อหัวของพวกเขาชนกับวัตถุ

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    อธิบายสิ่งที่ Enum.UserCFrame มีความรับผิดชอบในการใส่ใน VR

  • อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    อธิบายว่าผู้ใช้กำลังใช้อุปกรณ์เสมือนจริงหรือไม่

วิธีการ

อีเวนต์

คุณสมบัติ

AutomaticScaling

อ่านพร้อมๆ กัน

เมื่อตั้งค่าเป็น Enum.VRScaling.World , Camera.HeadScale ปรับให้ขนาดของโลกเห็นได้จากมุมมองของอวตารผู้เล่นที่มีอวตารขนาดเล็กจะรับรู้วัตถุรอบตัวเป็นใหญ่กว่าผู้เล่นที่มีอวตารขนาดใหญ่

AvatarGestures

อ่านพร้อมๆ กัน

เมื่อตั้งค่าเป็นจริง ผู้เล่น VR เฮดเซ็ท

คุณสมบัตินี้ต้องถูกตั้งค่าบนเซิร์ฟเวอร์

อ่านพร้อมๆ กัน

FadeOutViewOnCollision

อ่านพร้อมๆ กัน

เมื่อถูกต้อง มุมมองของผู้เล่น VR จะจางไปเป็นสีดําเมื่อหัวของพวกเขาชนกับวัตถุคุณสมบัตินี้ป้องกันไม่ให้ผู้เล่นสามารถมองเห็นผ่านผนังในขณะที่อยู่ใน VRค่าเริ่มต้นคือจริง

GuiInputUserCFrame

ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัตินี้อธิบายสิ่งที่ Enum.UserCFrame มีความรับผิดชอบในการใส่ใน อินสแตนซ์หากหูฟัง VR เป็นผู้รับผิดชอบ ค่าของคุณสมบัตินี้จะเป็น Enum.UserCFrame.Head

เพื่อตรวจสอบว่า Roblox ตรวจพบอุปกรณ์ VR ใดหรือไม่ซึ่งจะเป็นผู้รับผิดชอบในการป้อนใน 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()คุณยังสามารถตอบสนองต่อการเคลื่อนไหวของอุปกรณ์ VR โดยใช้เหตุการณ์ 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

คุณสมบัตินี้สามารถใช้ได้เฉพาะใน 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 ที่กำหนดไว้โหมดที่ส่งคืนบ่งบอกถึงวิธีที่ผู้ใช้โต้ตอบกับแท็บเล็ตเพื่อเล่นเกม

นอกจากนี้ยังสามารถใช้ร่วมกับวิธีและอีเวนต์ VR หลายอย่าง UserInputService

วิธีนี้จะทำงานได้เฉพาะเมื่อใช้ใน 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 ที่เชื่อมต่อสามารถทำได้โดยการเปลี่ยน CFrame ของตัวละครในเกมของผู้ใช้ให้ตรงกับ CFrame ของอุปกรณ์ VR ที่กำหนดโดยใช้ตัวเลือก UserCFrame และ CFrame ของอาร์กิวเมนต์ค่าที่ส่งโดยเหตุการณ์

VRService ยังให้กิจกรรม UserCFrameChanged ที่จะเปิดใช้งานโดยอัตโนมัติเมื่อ CFrame ของอุปกรณ์ VR ที่เชื่อมต่อเปลี่ยนแปลง, ตราบใดที่ใช้ใน LocalScript .

วิธีนี้จะทำงานได้เฉพาะเมื่อใช้ใน 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 หลายอย่าง UserInputService

วิธีนี้จะทำงานได้เฉพาะเมื่อใช้ใน 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

()

วิธีนี้จะเปลี่ยนศูนย์กลางของหัวของผู้ใช้กลับไปที่ตำแหน่งปัจจุบันของหู 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 , ใช้เพื่อตรวจจับคำขอดังกล่าวนอกจากนี้ยังสามารถใช้ร่วมกับวิธีและอีเวนต์ VR หลายอย่าง UserInputService

วิธีนี้จะทำงานได้เฉพาะเมื่อใช้ใน 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) ของผู้ใช้เพื่อให้ผู้ใช้โต้ตอบกับเกมอย่างแตกต่างโดยใช้แท็บเล็ต

นอกจากนี้ยังสามารถใช้ร่วมกับวิธีและอีเวนต์ VR หลายอย่าง UserInputService

วิธีนี้จะทำงานได้เฉพาะเมื่อใช้ใน 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 สําหรับอุปกรณ์ VR ที่กําหนด Enum.UserCFrameมันยิงด้วยพิกัด 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.VRTouchpadMode ของ Enum.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

อีเวนต์นี้จะเกิดขึ้นเมื่อมีการเปลี่ยนแปลง Enum.UserCFrame เช่นเมื่อผู้ใช้ย้ายอุปกรณ์ VR ที่เชื่อมต่อสามารถใช้ร่วมกับ GetUserCFrame() เพื่อติดตาม CFrame พิกัดของอุปกรณ์ VR และเมื่อมันเปลี่ยน/ย้ายนอกจากนี้ยังสามารถใช้ร่วมกับกิจกรรมและวิธีการบริการ UserInputService ได้

เนื่องจากอีเวนต์นี้จะเกิดขึ้นในท้องถิ่นดังนั้นจึงสามารถใช้ได้เฉพาะใน LocalScript

พารามิเตอร์

ประเภทของอุปกรณ์ VR ที่เปลี่ยนไป

value: CFrame

พิกัด CFrame ที่ปรับปรุงแล้วของอุปกรณ์ VR หลังการเปลี่ยนแปลง


ตัวอย่างโค้ด

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)