VRService

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

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

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

VRService รับผิดชอบในการจัดการการโต้ตอบระหว่าง Roblox และ VR (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``Class.Camera.HeadScale อวาตาร์ผู้เล่นที่มีอวตาร์ขนาดเล็กจะรับรู้วัตถุรอบตั

AvatarGestures

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

เมื่อตั้งค่าไว้ที่ true ผู้เล่น VR เฮดเซ็ท

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

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

FadeOutViewOnCollision

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

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

GuiInputUserCFrame

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

สมบัตินี้อธิบายว่า Enum.UserCFrame รับผิดชอบสำหรับการป้อนข้อมูลใน VR โดยเฉพาะ เช่น หาก 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 เท่านั้น

พารามิเตอร์

เครื่องมือสแน็ป Enums.VRTouchpad|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 ที่เชื่อมต่อได้ สิ่งนี้สามารถ

VRService ยังให้เหตุการณ์ UserCFrameChanged ที่เกิดขึ้นอัตโนมัติเมื่อ CFrame ของอุปกรณ์ VR ที่เชื่อมต่อเปลี่ยนแปลง โดยใช้ใน 0>

วิธีนี้จะทำงานเฉพาะใน LocalScript เท่านั้น

พารามิเตอร์

UserCFrame|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 อุปกรณ์สามารถใช้เพื่อตรวจสอบว่า 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

void

วิธีนี้จะนำ CFrame ของหัวผู้ใช้กลับไปยังตำแหน่งปัจจุบันของหมวก VR ที่สวมใส่โดยผู้ใช้ เฮดเซ็ท

พฤติกรรมนี้เหมือนกันกับ UserInputService:RecenterUserHeadCFrame()

วิธีนี้จะทำงานเฉพาะใน LocalScript เท่านั้น


ส่งค่ากลับ

void

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

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

วิธีนี้ขอให้การนำทางไปยัง CFrame โดยใช้ Enum.UserCFrame เป็นต้นที่สำหรับวิธีการจัดการ VR ในเกมของคุณโดยการให้วิธีการเห็นวิธีการนำทางจากอุปกรณ์ V

VRService มีเหตุการณ์ที่คล้ายคลึงกัน, NavigationRequested ใช้เพื่อตรวจจับคำขอเช่นนี้ นี่ยังสามารถใช้ร่วมกับวิธีการและเหตุการณ์ต่างๆ ของ Class.UserInputService ได้

วิธีนี้จะทำงานเฉพาะใน LocalScript เท่านั้น

พารามิเตอร์

cframe: CFrame

คองของ CFrame ที่ระบุ

inputUserCFrame: Enum.UserCFrame

อุปกรณ์ VR สำหรับการนำทาง


ส่งค่ากลับ

void

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

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

วิธีนี้ตั้งโหมดของ Enum.VRTouchpad ไว้ที่ Enum.VRTouchpadMode ต้องใช้เพื่อเปลี่ยนโหมดของผู้ใช้ให้เป็นโหมดของ VR ผู้ใช้ใช้งานได้โดยการใช้ 1>แท็ชแพด1> เพื่

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

วิธีนี้จะทำงานเฉพาะใน LocalScript เท่านั้น

พารามิเตอร์

The specified VRTouchpad คุณต้องการตั้งค่าโหมดของ.

โหมดที่คุณต้องการตั้ง VRTouchpad ให้


ส่งค่ากลับ

void

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

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 และ

เหตุการณ์นี้สามารถใช้ร่วมกับเหตุการณ์และวิธีการให้บริการ 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 ที่เชื่อมต่อ ตัวอย่างเช่

เนื่องจากเหตุการณ์นี้เกิดขึ้นในพื้นที่ของเราเอง จึงสามารถใช้ได้ใน 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() เพื่อติดต

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

พารามิเตอร์

The UserCFrame กำลังเปิดใช้งานหรือปิดใช้งาน

enabled: bool

ตัวเลือกที่แสดงว่า 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)