VR Grip Detection

Right now im working on a vr gun system, I have all the other things like firing the gun and ejecting the magazine. Im trying to add a feature where there is a ammo pouch on your hip and you would have to press the grip on the vr controller to take one out but i have no idea on how to detect that. Any ideas on how to achive that? Help is greatly appreciated.

1 Like

If this helps.

EDIT: This might be for HTC Vive

Im im trying to say, like in pavlov where you put your hand inside of the pouch and press trigger you get a magazine.

So your saying you need to know how to program the magazine ?

(Great example btw)

You could use UserInputService and when you press ButtonR1 and the hand is on the pouch (using GetTouchingParts) you can weld a part to a certain point on the hand

Blockquote script.Parent.Touched:connect(function(hit)
if hit.Name == (“Left Arm”) and Enum.KeyCode == Enum.KeyCode.ButtonL2 then

I tried doing this for one of the lines of code, it did not seem to work and i have no idea if im doing it right.
image
The entire code is

Blockquotelocal GUN = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA(“Tool”)
local char = game.Players.LocalPlayer.Character
local vrmags = game.ReplicatedStorage[“VR_GUN-MAGS”]
local Input = game:GetService(“UserInputService”)
local weld = Instance.new(“Weld”)
script.Parent.Touched:connect(function(hit)
if hit.Name == (“Left Arm”) and Enum.KeyCode == Enum.KeyCode.ButtonL2 then
local canrel2 = GUN:GetAttribute(“CANRELOAD”)
local canrel = GUN:GetAttribute(“MAGOUT”)
if canrel == true or canrel2 == false then
print (“cant rel”)
else
weld.Name = (“Magweld”)
vrmags.M3GG.MAG_VR:Clone().Parent = script.Parent.Parent.Magazines
script.Parent.Parent.Magazines.MAG_VR.Attachment.Parent = script.Parent.Parent[“Left Arm”]
weld.Parent = script.Parent.Parent[“Left Arm”]
weld.Part0 = script.Parent.Parent[“Left Arm”]
weld.Part1 = script.Parent.Parent.Magazines.MAG_VR
script.Parent.Parent.Magazines.MAG_VR.Position = script.Parent.Parent[“Left Arm”].Attachment.WorldPosition
script.Parent.Parent.Magazines.MAG_VR.Orientation = script.Parent.Parent[“Left Arm”].Attachment.WorldOrientation
script.Parent.Parent[“Left Leg”].Pouch.Equip:Play()
end
end
end)

1 Like

I see what you are going for. Maybe detect using UserInputService first to detect when they grip. then use GetTouchingParts() and see if the left hand is being pulled on top of the pouch.

If it didnt work do you mind sending me the error it said in Output?

GetTouchingParts() Only detects parts that collide with it. and there isnt a error in the console at all. :man_shrugging: