Attaching vr camera to players head

Hello developers I am trying to tie the players head to rotate to the same CFrame as the players vr camera. So far all my script does is glitch the player into the ground heres my script.


The only vr development experience i have is with unity so I would greatly apricate help with this.

I would do

local player = game:GetService("Players").LocalPlayer

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    player.Character:FindFirstChild("Head").CFrame = CFrame.new(camera.CFrame.LookVector)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

Also make sure that can collide and cantouch is off on the head.

1 Like

The players character still seems to get stuck in the ground as well as the head not following the rotation of the camera

Maybe this?

local player = game:GetService("Players").LocalPlayer

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    player.Character:FindFirstChild("Head").CFrame = camera.CFrame + Camera.CFrame.LookVector
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

this time it seems to be locked in front of the camera and acts like its anchored

How about this?

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
player.CameraMode = Enum.CameraMode.LockFirstPerson

local function renderStepped()
    camera.CFrame = humanoidRootPart.CFrame + Vector3.new(0,2,0)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

It’s now acting as if it was a default camera in first person the head is locked with the body and can’t look up or down. (as in the character rotates entirely)

What about this?

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    local headCFrame = game:GetService("UserInputService"):GetUserCFrame(Enum.UserCFrame.Head)
    local headCameraCFrame = camera.CFrame * CFrame.new(headCFrame.p * camera.HeadScale) * (headCFrame - headCFrame.p)
    local activeOffset = Vector3.new(0,5,0).Value + character.Torso.Position.Value
    character.CFrame = hcf + activeOffset
    cam.CFrame = CFrame.new(activeOffset)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

Also make sure the character is in R6

image
repeating error on line 11

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    local headCFrame = game:GetService("UserInputService"):GetUserCFrame(Enum.UserCFrame.Head)
    local headCameraCFrame = camera.CFrame * CFrame.new(headCFrame.p * camera.HeadScale) * (headCFrame - headCFrame.p)
    local activeOffset = Vector3.new(0,5,0) + character.Torso.Position
    character.CFrame = hcf + activeOffset
    cam.CFrame = CFrame.new(activeOffset)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

what is the hcf suppose to be? it’s not a variable

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    local headCFrame = game:GetService("UserInputService"):GetUserCFrame(Enum.UserCFrame.Head)
    local headCameraCFrame = camera.CFrame * CFrame.new(headCFrame.p * camera.HeadScale) * (headCFrame - headCFrame.p)
    local activeOffset = Vector3.new(0,5,0) + character.Torso.Position
    character.CFrame = headCameraCFrame + activeOffset
    camera.CFrame = CFrame.new(activeOffset)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)

Now I get the error CFrame is not a valid member of Model “Workspace.WADSCOOOll” (WADSCOOLL is my characters name) on line 12

local player = game:GetService("Players").LocalPlayer
local character = player.Character

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    local headCFrame = game:GetService("UserInputService"):GetUserCFrame(Enum.UserCFrame.Head)
    local headCameraCFrame = camera.CFrame * CFrame.new(headCFrame.p * camera.HeadScale) * (headCFrame - headCFrame.p)
    local activeOffset = Vector3.new(0,5,0) + character.Torso.Position
    character.HumanoidRootPart.CFrame = headCameraCFrame + activeOffset
    camera.CFrame = CFrame.new(activeOffset)
end
game:GetService("RunService").RenderStepped:Connect(renderStepped)
1 Like

My headsets display was flashing between black and the studio world and then it crashed

1 Like
local player = game:GetService("Players").LocalPlayer
local character = player.Character

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

local function renderStepped()
    local headCFrame = game:GetService("UserInputService"):GetUserCFrame(Enum.UserCFrame.Head)
    local headCameraCFrame = camera.CFrame * CFrame.new(headCFrame.p * camera.HeadScale) * (headCFrame - headCFrame.p)
    local activeOffset = Vector3.new(0,5,0) + character.Torso.Position
    character.HumanoidRootPart.CFrame = headCameraCFrame + activeOffset
    camera.CFrame = CFrame.new(activeOffset)
end
game:GetService("RunService").Heartbeat:Connect(renderStepped)
1 Like

Same result my headset is about to die so ill try again later, thank you so much for the help

2 Likes