When changing the HeadScale to anything higher then 1 the head outruns the camera (VR Programming)

I cant seem to figure out how to make the camera stay inside the head when i try to upscale the head to anything higher then 1 studs.

This is the code:

local Player = game.Players.LocalPlayer
local VRService = game:GetService("VRService")
local Camera = workspace.CurrentCamera
local Core = require(game.ReplicatedStorage.Classes.Core)
local PlayerValues = Player:WaitForChild("PlayerValues")
local Character = PlayerValues:WaitForChild("Character")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

Camera.CFrame = workspace.Base.CFrame

if Core.GetDeviceStatus() == "VR" then
	game.ReplicatedStorage.Events.CreateCharacter:FireServer("VR")
else
	game.ReplicatedStorage.Events.CreateCharacter:FireServer("Normal")
end



repeat wait() until PlayerValues.Type.Value == "VR" or PlayerValues.Type.Value == "Normal"
if PlayerValues.Type.Value == "VR" then
	local Character = PlayerValues.Character.Value
	
	game.StarterGui:SetCore("VRLaserPointerMode", 0)
	game.StarterGui:SetCore("VREnableControllerModels", false)
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
	UIS.MouseIconEnabled = false
	Camera.CameraType = Enum.CameraType.Scriptable
	
	local ReplicatedChar = Character:Clone()
	ReplicatedChar.Parent = game.ReplicatedStorage
	
	local Head = Character.Head
	local RightHand = Character.RightHand
	local LeftHand = Character.LeftHand
	local HeadScale = 1
				
	RunService.RenderStepped:Connect(function()
		local HeadCF = VRService:GetUserCFrame(Enum.UserCFrame.Head)
		local RightHandCF = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
		local LeftHandCF = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
		
		Head:SetPrimaryPartCFrame(Camera.CFrame * CFrame.new(HeadCF.p * HeadScale) * (HeadCF - HeadCF.p))
		RightHand:SetPrimaryPartCFrame(Camera.CFrame * CFrame.new(RightHandCF.p * HeadScale) * (RightHandCF - RightHandCF.p))
		LeftHand:SetPrimaryPartCFrame(Camera.CFrame * CFrame.new(LeftHandCF.p * HeadScale) * (LeftHandCF - LeftHandCF.p))
		
		for i, part in pairs(Character:GetDescendants()) do
			if part:IsA("Model") then
				game.ReplicatedStorage.Events.UpdatePart:FireServer(part, part.PrimaryPart.CFrame)
			end
		end
	end)	
end

If anyone has any insight please let me know as it would be very helpful

1 Like

Im stupid I completely forgot to change the cameras HeadScale itself.