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.
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 플레이어의 시점이 머리가 물체와 충돌할 때 검은색으로 사라집니다.
VR에서 입력할 내용을 설명하는 Enum.UserCFrame을 설명합니다.
사용자가 가상 현실 기기사용하는지 여부를 설명합니다.
메서드
지정된 VRTouchpad의 모드를 나타내는 VRTouchpadMode를 반환합니다.
특정 가상 현실 장치의 위치 및 방향을 실제 세계 공간의 포인트에서 오프셋으로 설명하는 CFrame을 반환합니다.
지정된 Enum.UserCFrame가 듣기에 사용 가능하면 진실을 반환합니다.
사용자가 착용하고 있는 VR 헤드셋의 현재 위치로 CFrame를 재설정합니다.
지정된 CFrame 를 시각화 파라볼라의 원본으로 사용하여 지정된 Enum.UserCFrame 에 요청 탐색을 수행합니다.
지정된 Enum.VRTouchpad 모드를 지정된 Enum.VRTouchpadMode 모드로 설정합니다.
이벤트
탐색이 요청되면 VRService에서 해고됩니다.
Enum.VRTouchpadMode 변경으로 인해 발생하는 화재. Enum.VRTouchpad 변경으로 인해 발생하는 화재.
Enum.UserCFrame. when a changes.
Enum.UserCFrame가 활성화되거나 비활성화되면 발생합니다.
속성
AutomaticScaling
Enum.VRScaling.World 로 설정되면 Camera.HeadScale 아바타의 관점에서 세계의 규모가 보이도록 조정됩니다.아바타가 작은 플레이어는 아바타가 큰 플레이어보다 주변의 개체를 더 크게 인식합니다.
ControllerModels
FadeOutViewOnCollision
참이면 VR 플레이어의 시점이 머리가 물체와 충돌할 때 검은색으로 사라집니다.이 속성은 VR 상태에서 플레이어가 벽을 통해 볼 수 없도록 합니다.기본값은 true입니다.
GuiInputUserCFrame
이 속성은 VR에서 입력할 내용에 대해 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!".
local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("No VR device detected!")
end
LaserPointer
ThirdPersonFollowCamEnabled
VREnabled
이 속성은 사용자가 VR(가상 현실) 기기사용하는지 여부를 설명합니다.
VR 장치가 활성화되면 UserInputService:GetUserCFrame()와 같은 메서드를 통해 위치와 이동을 상호작용할 수 있습니다.또한 UserInputService.UserCFrameChanged 이벤트를 사용하여 VR 장치 이동에 반응할 수 있습니다.
local UserInputService = game:GetService("UserInputService")local isUsingVR = UserInputService.VREnabledif isUsingVR thenprint("User is using a VR headset!")elseprint("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.
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 메서드와 이벤트와 함께 사용할 수도 있습니다.
이 메서드는 LocalScript에서 사용될 때만 작동합니다.
매개 변수
지정된 VRTouchpad .
반환
지정된 VRTouchpad의 모드.
코드 샘플
This example retrieves and prints the name of the user's current VRTouchpad.Left touchpad mode.
local VRService = game:GetService("VRService")
VRService:GetTouchpadMode(Enum.VRTouchpad.Left)
GetUserCFrame
이 메서드는 특정 가상 현실(VR) 장치의 위치와 방향을 실제 세계 공간의 오프셋으로 설명하는 CFrame 메서드를 반환합니다.이 메서드는 연결된 VR 기기이동을 얻고 추적하기 위해 게임에 VR 호환성을 구현할 때 사용해야 합니다.
메서드를 사용하여 개발자는 연결된 VR 장치의 위치에 해당하는 사용자 내 게임 기기재배치하는 등의 기능을 구현할 수 있습니다.이는 UserCFrame 열거형과 이벤트에서 전달된 CFrame 및 CFrame 값 인수를 사용하여 게임 내 사용자 캐릭터의 CFrame을 변경하여 지정된 VR 장치의 CFrame과 일치시키면 수행할 수 있습니다.
VRService 또한 연결된 VR 장치의 UserCFrameChanged 변경 시 자동으로 발생하는 CFrame 이벤트를 제공하며, 연결된 VR 장치의 LocalScript에서 사용되는 한 계속됩니다.
이 메서드는 LocalScript에서 사용될 때만 작동합니다.
매개 변수
지정된 UserCFrame .
반환
코드 샘플
This example positions a part at the player's left hand, assuming Camera.HeadLocked = true
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)가 수신할 수 있는 경우 true를 반환합니다.VR 기기(예: Enum.UserCFrame.Head)가 사용자의 게임에 연결되었는지 여부를 결정하는 데 사용할 수 있습니다.
이는 여러 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!".
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.
local VRService = game:GetService("VRService")
VRService:RecenterUserHeadCFrame()
RequestNavigation
이 메서드는 지정된 CFrame 를 시각화 파라볼라의 원본으로 사용하여 지정된 Enum.UserCFrame 에 대한 탐색을 요청합니다.가상 현실(VR)을 게임에 통합하여 사용자의 VR 장치에서 목적지까지 이동 경로를 시각화할 수 있는 수단을 제공하여 게임에 VR을 통합할 수 있습니다.
VRService 에는 이러한 요청을 감지하는 데 사용되는 유사한 이벤트가 있습니다, NavigationRequested .이는 여러 UserInputService 메서드와 이벤트와 함께 사용할 수도 있습니다.
이 메서드는 LocalScript에서 사용될 때만 작동합니다.
매개 변수
탐색이 요청된 VR 장치.
반환
코드 샘플
이 예제는 사용자의 UserCFrame.Head 좌표에서 탐색을 요청하고, 이름이 Part인 CFrame 좌표로 이동합니다.
참고: 이것이 작동하려면 게임의 작업 공간에 이름이 NavigationDestination인 파트가 있어야 합니다.
local VRService = game:GetService("VRService")
local destination = workspace:FindFirstChild("NavigationDestination")
VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)
SetTouchpadMode
이 메서드는 지정된 Enum.VRTouchpad 모드를 지정된 Enum.VRTouchpadMode로 설정합니다.사용자의 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.
local VRService = game:GetService("VRService")
VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)
이벤트
NavigationRequested
이 이벤트는 특정 VR 장치에 대해 VRService 탐색이 요청될 때 발생합니다.This event fires when navigation is requested from for a specified Enum.UserCFrame VR 기기.그것은 좌표와 지정된 장치가 탐색을 요청하는 것을 나타내는 특정 코드로 발사됩니다.
이 이벤트는 UserInputService.
이 이벤트는 로컬로 발생하기 때문에, 이를 사용하려면 LocalScript에서만 가능합니다.
매개 변수
탐색이 요청된 VR 장치를 나타냅니다.
코드 샘플
This example prints the name of the UserCFrame VR device making the request, and the CFrame coordinates passed.
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.
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가 변경될 때 발생합니다.VR 기기GetUserCFrame() 좌표와 변경/이동 시기를 추적하기 위해 CFrame 와 함께 사용할 수 있습니다.또한 UserInputService 서비스 이벤트와 메서드와 함께 사용할 수 있습니다.
이 이벤트는 로컬로 발생하기 때문에, 이를 사용하려면 LocalScript에서만 가능합니다.
매개 변수
변경된 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.
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가 활성화되거나 비활성화되고 있습니다.
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.
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)