Help with simple VR hands Rotation and movement

I’m making a VR game and I’m having problems with rotation and movement
I have a simple system set up where the instance hands follow the player’s hand movements and it’s all kind of like the game VR Hands. But I have a problem where I don’t know how to implement Rotation and Movement.

I tried using some rotation scripts but it weirdly offsets the player’s hands and they won’t track properly once rotated, here’s the rotation code

UserInputService.InputChanged:Connect(function(input)

if input.UserInputType == Enum.UserInputType.Gamepad1 then

	if input.KeyCode == Enum.KeyCode.Thumbstick1 then

		thumbX = math.floor(input.Position.X  * 10) / 20
		thumbY = math.floor(input.Position.Y  * 10) / 20

	elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then

		if math.abs(input.Position.Y) > math.abs(input.Position.X) then
			thumbZ = math.floor(input.Position.Y * 10) / 20
		elseif not rotated and math.abs(input.Position.X) > 0.9 then
			rotated = true
			Camera.CFrame = Camera.CFrame * CFrame.Angles(0,-input.Position.X/3,0)
		end

	end


end
end)

and here’s the hand tracking

UserInputService.UserCFrameChanged:Connect(function(part, move)
if part == Enum.UserCFrame.LeftHand then
	LeftHand.CFrame = Camera.CFrame * move + move.Position*(HeadScale-1)
elseif part == Enum.UserCFrame.RightHand then
	RightHand.CFrame = Camera.CFrame * move + move.Position*(HeadScale-1)
end
end)

if there’s any way to fix the offset or a different rotation script I could use, I would greatly appreciate it

I’m trying to understand what you’re trying to achieve here, are you trying to just position the hands alongside their rotation, with headscale accounted for? If so, VRService Docs has example code on how to do this:

local VRService = game:GetService("VRService")

local part = workspace.Part

local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale

part.CFrame = workspace.CurrentCamera.CFrame * handOffset
1 Like

I got the hand tracking part, but when I rotate the camera using the thumbstick controls, the hand tracking gets offset and I’m not sure how to fix it

I got it to work, thank you very much

Last thing, do you know any way I could make simple floating movement like VR Hands?

I salvaged this movement script and modified it

UserInputService.InputChanged:Connect(function(input)

if input.UserInputType == Enum.UserInputType.Gamepad1 then

	if input.KeyCode == Enum.KeyCode.Thumbstick1 then

		thumbX = math.floor(input.Position.X  * 10) / 20
		thumbY = math.floor(input.Position.Y  * 10) / 20
		
		Camera.CFrame = Camera.CFrame * CFrame.new(thumbX,0,-thumbY)

	elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
		
		thumbY = math.floor(input.Position.Y  * 10) / 20
		
		Camera.CFrame = Camera.CFrame * CFrame.new(0,thumbY,0)

		if math.abs(input.Position.Y) > math.abs(input.Position.X) then
			thumbZ = math.floor(input.Position.Y * 10) / 20
		elseif not rotated and math.abs(input.Position.X) > 0.9 then
			rotated = true
			Camera.CFrame = Camera.CFrame * CFrame.Angles(0,-input.Position.X/3,0)
		end

	end


end
end)

All I need is for the movement to relate to the where the player’s head is facing, any help?

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