UserCFrameChanged
For thread safety, this property is not safe to read in an unsynchronized thread.
The UserCFrameChanged event fires when the DataType/CFrame
of a VR device changes.
This event can be used to track the movement of a connected VR device.
Using the event, you can implement features such as moving the user’s in-game character limbs as the user moves their VR device. This can be done by changing the CFrame of the user’s in-game limbs to match the CFrame changes of the VR device using the Enum/UserCFrame
enum and CFrame value arguments passed by the event.
To retrieve the DataType/CFrame
of a connected VR device, use UserInputService/GetUserCFrame
.
As the event fires locally, it can only be used in a LocalScript
.
See also
VRService
, used to implement support, including an identical eventVRService/UserHeadCFrameChanged
Camera/HeadLocked
, when this property is true theCamera
will automatically track the head motion of a player using a VR deviceCamera/GetRenderCFrame
, a function which retrieves theDataType/CFrame
theCamera
is being orientated at, including the impact of VR devices
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
A |
||
|
A |
Code Samples
VR Head Tracking
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 Player/Character|character’s
head.
The example first check if the user is using a VR device by checking the value of the UserInputService/VREnabled|VREnabled
property. This example only works if the user is using a VR headset.
To determine the initial DataType/CFrame
of the character’s head, the code sample calls UserInputService/GetUserCFrame|GetUserCFrame
and passes Enum/UserCFrame|Enum.UserCFrame.Head
as the argument.
To update the head’s CFrame whenever the user’s VR headset moves, the example connects the UserInputService/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 DataType/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
.