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