I have custom vr hands which can grab and let go of stuff but the positioning is offset
how can i make it so different objects have different orientation based on the name?
ive been looking for weeks and i just now thought of posting my problem
here is my code
local InputService = game:GetService("UserInputService")
local Camera = workspace.CurrentCamera
Camera.HeadScale = 5
local RightMotors = {}
local LeftMotors = {}
for i,x in pairs(workspace.RightHand:GetDescendants()) do
if x:IsA("Motor6D") then
table.insert(RightMotors,{x,x.C1})
end
end
for i,x in pairs(workspace.LeftHand:GetDescendants()) do
if x:IsA("Motor6D") then
table.insert(LeftMotors,{x,x.C1})
end
end
local function BendFingers(Hand,Rot)
local joints = (Hand=="Right" and RightMotors) or (Hand=="Left" and LeftMotors)
local Rot = (Hand=="Right" and -Rot) or (Hand=="Left" and Rot)
for i,x in pairs(joints) do
if x[1].Name == "ThumbJoint" then
x[1].C1 = x[2] * CFrame.Angles(math.rad(45*Rot),math.rad(10*Rot),0)
else
x[1].C1 = x[2] * CFrame.Angles(math.rad(25*Rot),0,0)
end
end
end
local HeadPosition = nil
local function Track(Type, Value)
if Type == Enum.UserCFrame.RightHand then
workspace.RightHand.Hand.CFrame = Camera.CoordinateFrame * (CFrame.new(Value.p*(Camera.HeadScale-1))*Value) * CFrame.Angles(0,math.pi,0)
end
if Type == Enum.UserCFrame.LeftHand then
workspace.LeftHand.Hand.CFrame = Camera.CoordinateFrame * (CFrame.new(Value.p*(Camera.HeadScale-1))*Value) * CFrame.Angles(0,math.pi,math.pi)
end
if Type == Enum.UserCFrame.Head then
HeadPosition = Camera.CoordinateFrame * (CFrame.new(Value.p*(Camera.HeadScale +5))*Value)
end
end
InputService.UserCFrameChanged:Connect(Track)
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
local final = {}
for i,x in pairs(results) do if x.Parent ~= part.Parent and not x.Locked then table.insert(final,x) end end
return final
end
local function SearchTable(tab,val,delete)
local Found = false
for i,x in pairs(tab) do
if x == val then
Found = true
if delete then table.remove(tab,i) end
break
end
end
return Found
end
local Holding = {}
local function GrabObject(Part,Input)
spawn(function()
if not SearchTable(Holding,Part,false) then
local eatdb = true
while Input.Position.Z > 0.1 do
if Part.Anchored then
break
end
Part.CFrame = workspace.RightHand.HB.CFrame
spawn(function()
end)
game:GetService("RunService").RenderStepped:Wait()
end
SearchTable(Holding,Part,true)
end
end)
end
local function HandleInput(Input)
if Input.KeyCode == Enum.KeyCode.ButtonR1 then
local Parts = GetTouchingParts(workspace.RightHand.HB)
for i,x in pairs(Parts) do
print(Parts[1].Name)
GrabObject(x,Input)
end
BendFingers("Right",Input.Position.Z)
end
if Input.KeyCode == Enum.KeyCode.ButtonR1 then
BendFingers("Left",Input.Position.Z)
end
end
InputService.InputChanged:Connect(HandleInput)
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("VRLaserPointerMode", 0)
StarterGui:SetCore("VREnableControllerModels", false)
its the same for the left hand but the name of it is LeftHand (ex. workspace.LeftHand.Hb.Position…)
any help would be appreciated!