VR hands not tracking

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make VR hands that use a glove mesh that track the controllers and have physics collisions. (don’t pass through walls, knock stuff down, etc)
  2. What is the issue? Include screenshots / videos if possible!
    It’s just not working. Controllers are being tracked as if you select the AlignOrientation or AlignPosition, it is being tracked in game. It is just for some reason, really far down from the player. (under the map)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    It has been 6 hours.
local VRService = game:GetService("VRService")
local UserInputService = game:GetService("UserInputService")
local starterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camera = workspace.CurrentCamera

camera.CameraType = "Scriptable"
camera.HeadScale = 1

local SettingsModule = require(script.SettingsModule)
local isDebug = SettingsModule.DEBUG_MODE

if not VRService.VREnabled and not isDebug then
	game.Players.LocalPlayer:Kick("VR NOT DETECTED | PLEASE REJOIN ON A VIRTUAL REALITY HEADSET.")
end

local Player = script.Parent.Parent
local Char = workspace.GameFolder.NonVrCharModels:WaitForChild(Player.Name)

Char:WaitForChild("HumanoidRootPart").Anchored = true
camera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position)

starterGui:SetCore("VRLaserPointerMode", 0)
starterGui:SetCore("VREnableControllerModels", false)

local function createHand(handType: R_L_W?)
	if handType == "L" then
		local selectedHand = ReplicatedStorage.Resources.HandModels.LeftHandFolder.handL
		local handL = selectedHand:Clone()
		local attachment0 = Instance.new("Attachment")
		attachment0.Name = "Attachment0"
		attachment0.Parent = handL.glove
		handL.Parent = Char
		handL.CFrame = Char.HumanoidRootPart.CFrame
		if isDebug then
			warn("CreateHand function called: handType = " .. handType)
		end
		print(handL)
		return handL
	elseif handType == "R" then
		local selectedHand = ReplicatedStorage.Resources.HandModels.RightHandFolder.handR
		local handR = selectedHand:Clone()
		handR.Parent = Char
		handR.CFrame = Char.HumanoidRootPart.CFrame
		if isDebug then
			warn("CreateHand function called: handType =" .. handType)
		end
		return handR
	--[[
	elseif handType == "W" then
		local selectedHand = script:FindFirstChild("RightHand")
		local RightHand = selectedHand:Clone()
		RightHand.CFrame = Char.HumanoidRootPart.CFrame
	--]]
	end
end

local handLeft = createHand("L")
local handRight = createHand("R")


VRService.UserCFrameChanged:Connect(function(part, move)
	if part == Enum.UserCFrame.LeftHand then

		warn("part = enum.usercframe.lefthand")
		
		-- handLeft.CFrame = camera.CFrame * cFrame
		
		local alignPosition = handLeft.glove:FindFirstChildOfClass("AlignPosition") or Instance.new("AlignPosition")
		alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
		alignPosition.Attachment0 = handLeft.glove.Attachment0
		alignPosition.Position = move.Position
		alignPosition.Responsiveness = 200
		alignPosition.Parent = handLeft.glove
	
		local alignOrientation = handLeft.glove:FindFirstChildOfClass("AlignOrientation")
			or Instance.new("AlignOrientation")
		alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
		alignOrientation.Attachment0 = handLeft.glove.Attachment0
		alignOrientation.CFrame = move
		alignOrientation.Responsiveness = 200
		alignOrientation.Parent = handLeft.glove
	elseif part == Enum.UserCFrame.RightHand then

		warn("part = enum.usercframe.righthand")
		
		-- handRight.CFrame = camera.CFrame * cFrame

		local alignPosition = handRight.glove:FindFirstChildOfClass("AlignPosition") or Instance.new("AlignPosition")
		alignPosition.Mode = Enum.PositionAlignmentMode.TwoAttachment
		alignPosition.Attachment0 = handRight.glove.Attachment0
		alignPosition.Position = move.Position
		alignPosition.Responsiveness = 200
		alignPosition.Parent = handRight.glove

		local alignOrientation = handRight.glove:FindFirstChildOfClass("AlignOrientation")
			or Instance.new("AlignOrientation")
		alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
		alignOrientation.Attachment0 = handRight.glove.Attachment0
		alignOrientation.CFrame = move
		alignOrientation.Responsiveness = 200
		alignOrientation.Parent = handRight.glove
	end
end)

--[[
UserInputService.UserCFrameChanged:Connect(function(part, move)
	if part == Enum.UserCFrame.LeftHand then
		handLeft.CFrame = camera.CFrame * move
	elseif part == Enum.UserCFrame.RightHand then
		handRight.CFrame = camera.CFrame * move
	end
end)
--]]
--[[
VRService.UserCFrameChanged:Connect(function(part, move)
	camera.CFrame = CFrame.new(Char.HumanoidRootPart.Position) + Vector3.new(0, 5, 0)
	if part == Enum.UserCFrame.LeftHand then
		Char.HumanoidRootPart.LHand.WorldCFrame = camera.CFrame * move
	elseif part == Enum.UserCFrame.RightHand then
		Char.HumanoidRootPart.RHand.WorldCFrame = camera.CFrame * move
	end
end)
--]]
2 Likes

I believe the issue stems with the position of the VR controllers, these positions are relative to the VR headset’s position. You’ll need to transform these positions into the game’s coordinate system using the CFrame of the camera like in this example:

VRService.UserCFrameChanged:Connect(function(part, move)
    local globalCFrame = camera.CFrame * move

    if part == Enum.UserCFrame.LeftHand then
        Char.HumanoidRootPart.LHand.CFrame = globalCFrame
    elseif part == Enum.UserCFrame.RightHand then
        Char.HumanoidRootPart.RHand.CFrame = globalCFrame
    end
end)
1 Like

I just noticed you have tried multiple things already, not too sure if this will help.

1 Like

It would work, as I’ve already tried that and it works, but there are no wall or physics collisions. I want something similar to VR Hands, where you can’t knock people off the parkour due to a wall and it will just block your hands.

1 Like

I have got the VR hands to track correctly to the controllers. I added the positions instead of multiplying them and cleaned up the code so it’s not redefining properties every frame.

VRService.UserCFrameChanged:Connect(function(part, move)
	if part == Enum.UserCFrame.LeftHand then
		local alignPosition = handLeft.glove:FindFirstChildOfClass("AlignPosition")
		alignPosition.Position = camera.CFrame.Position + move.Position
	
		local alignOrientation = handLeft.glove:FindFirstChildOfClass("AlignOrientation")
		alignOrientation.CFrame = (camera.CFrame * move) * CFrame.Angles(-90, -90, 0)
	elseif part == Enum.UserCFrame.RightHand then
		local alignPosition = handRight.glove:FindFirstChildOfClass("AlignPosition")
		alignPosition.Position = camera.CFrame.Position + move.Position

		local alignOrientation = handRight.glove:FindFirstChildOfClass("AlignOrientation")
		alignOrientation.CFrame = (camera.CFrame * move) * CFrame.Angles(-90, 90, 0)
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.