VR Head default CFrame not centered

Hello. So I am starting on a VR game and am working on the head movements, but I’ve run into the problem of the camera not centered and being tilted when I load in.

Here is an example of what I mean:

This is with the headset facing completely straight.

Here is my code:


local VRService = game:GetService("VRService")
local UserInputService = game:GetService("UserInputService")
local Cam = workspace.CurrentCamera

local Character = game.Workspace.Character
local Head = Character.Head

HeadScale = 1
Cam = workspace.CurrentCamera
Cam.HeadScale = HeadScale

local cfH = VRService:GetUserCFrame(Enum.UserCFrame.Head)
Head.CFrame = (Cam.CFrame*CFrame.new(cfH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfH:ToEulerAnglesXYZ())

Sorry for the trouble and thanks for the help!

1 Like

You have to update the HeadCFrame with RunService.Heatbeat or VRService.UserCFrameChanged

try this:

local RunService = game:GetService("RunService")
local VRService = game:GetService("VRService")
local UserInputService = game:GetService("UserInputService")
local Cam = workspace.CurrentCamera

local Character = game.Workspace.Character
local Head = Character.Head

HeadScale = 1
Cam = workspace.CurrentCamera
Cam.HeadScale = HeadScale

RunService.Heartbeat:Connect(function()
    local cfH = VRService:GetUserCFrame(Enum.UserCFrame.Head)
    Head.CFrame = (Cam.CFrame*CFrame.new(cfH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfH:ToEulerAnglesXYZ())
end)

You should use RenderStepped instead of heartbeat for camera controlling, especially in VR where low frames can make you sick. Heartbeat is only 1/30th of a second, RenderStepped is every frame.

1 Like

Oh! I thought it was the opposite, Thank you!

I will try this as soon as i can. Thanks!

1 Like