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.
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())
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.