kalebxo

vr hands updated ;-;

Dec 8th, 2021
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. local plyrs = game:GetService("Players")
  2. local rs = game:GetService("RunService")
  3. local uis = game:GetService("UserInputService")
  4. local cam = workspace.Camera
  5. local headset
  6. local p
  7.  
  8. local bodybinds = {
  9. [Enum.UserInputType.MouseButton1] = "lHand",
  10. [Enum.UserInputType.MouseButton2] = "rHand",
  11. [Enum.KeyCode.W] = Vector3.new(0, 1, 0),
  12. [Enum.KeyCode.A] = Vector3.new(-1, 0, 0),
  13. [Enum.KeyCode.S] = Vector3.new(0, -1, 0),
  14. [Enum.KeyCode.D] = Vector3.new(1, 0, 0),
  15. [Enum.KeyCode.Q] = false,
  16. [Enum.KeyCode.E] = true,
  17. [Enum.KeyCode.LeftShift] = 1,
  18. [Enum.KeyCode.LeftControl] = 2,
  19. [Enum.KeyCode.LeftAlt] = 3
  20. }
  21.  
  22. local gesturebinds = {
  23. "Fist",
  24. "Index",
  25. "Thumb"
  26. }
  27.  
  28. local body = setmetatable({ -- least fav part of the script
  29. lastHand = "",
  30. lHand = {
  31. false,
  32. CFrame.new(-math.cos(math.pi / 4), -0.5, -math.sin(math.pi / 4)),
  33. 0
  34. },
  35. rHand = {
  36. false,
  37. CFrame.new(-math.cos(3 * math.pi / 4), -0.5, -math.sin(3 * math.pi / 4)),
  38. 0
  39. }
  40. }, {
  41. __call = function(t, k, mult)
  42. mult = mult or 1
  43.  
  44. local bind = bodybinds[k]
  45. if bind and headset then
  46. if typeof(bind) == "string" then
  47. t[bind][1] = mult > 0
  48.  
  49. lastHand = mult > 0 and bind or lastHand
  50.  
  51. elseif typeof(bind) == "Vector3" then
  52. headset.StickPosition += bind * mult
  53. elseif typeof(bind) == "boolean" then
  54. headset.Stick2 = mult > 0 and bind and 1 or 0
  55. elseif typeof(bind) == "number" and lastHand:len() > 0 then
  56. local gesture = lastHand:sub(1,1)..gesturebinds[bind]
  57.  
  58. if mult > 0 then
  59. headset[gesture] = headset[gesture] == 0 and 1 or 0
  60. end
  61. end
  62. end
  63. end
  64. })
  65.  
  66. local ind, nc, nind
  67.  
  68. local events = {}
  69.  
  70. local cfs = {
  71. [Enum.UserCFrame.Head] = CFrame.new(0, 0, 0),
  72. [Enum.UserCFrame.LeftHand] = CFrame.new(-1, 0, -1),
  73. [Enum.UserCFrame.RightHand] = CFrame.new(1, 0, -1)
  74.  
  75. }
  76.  
  77. local realVrService = game:GetService("VRService")
  78.  
  79. local fakeVrService = setmetatable({
  80. VREnabled = true,
  81. SetTouchpadMode = function()
  82. end,
  83. RecenterUserHeadCFrame = function()
  84. end,
  85. GetUserCFrameEnabled = function(cf)
  86. return true
  87. end,
  88. GetUserCFrame = function(cf)
  89. return cfs[cf] or CFrame.new(0, 0, 0)
  90. end
  91.  
  92. }, {
  93. __index = function(t, k)
  94. local real = ind(realVrService, k)
  95. if typeof(real) == "RBXScriptSignal" then
  96. events[k] = events[k] or {
  97. Name = k,
  98. Connect = function(t, f)
  99. t.Function = f
  100.  
  101. if t.Name == "UserCFrameChanged" then
  102. headset = debug.getupvalue(t.Function, 1)
  103.  
  104. debug.setupvalue(headset.UpdateHand, 5, setmetatable({}, {
  105. __index = function(t, k)
  106. return cam[k]
  107. end,
  108. __newindex = function(t, k, v)
  109. if cam.CameraType == Enum.CameraType.Scriptable and p then -- unfortunately the first time this will run may or may not be before the cameratype is set
  110. cam.CameraType = Enum.CameraType.Custom
  111. cam.CameraSubject = headset.Head
  112. end
  113.  
  114. if k ~= "CFrame" then -- fuck you
  115. cam[k] = v
  116. end
  117. end
  118. }))
  119.  
  120. cam:GetPropertyChangedSignal("CameraSubject"):connect(function()
  121. if cam.CameraSubject ~= headset.Head then
  122. cam.CameraSubject = headset.Head
  123. end
  124. end)
  125. end
  126.  
  127. end,
  128. Fire = function(t, ...)
  129. return t.Function(...)
  130. end
  131. }
  132.  
  133. return events[k]
  134. end
  135.  
  136. return real
  137. end,
  138. __call = function(t, method, vr, ...)
  139. return t[method](...)
  140. end
  141. })
  142.  
  143. ind = hookmetamethod(game, "__index", function(...)
  144. local t, k = ...
  145.  
  146. local scr = getcallingscript()
  147.  
  148. if t == realVrService and not (scr and ind(scr, "Name") == "CameraModule") then
  149. return fakeVrService[k]
  150. end
  151.  
  152. return ind(...)
  153. end)
  154.  
  155. nc = hookmetamethod(game, "__namecall", function(...)
  156. local t = ...
  157.  
  158. if t == realVrService then
  159. local method = getnamecallmethod()
  160. return fakeVrService(method, ...)
  161. end
  162.  
  163. return nc(...)
  164. end)
  165.  
  166. nind = hookmetamethod(game, "__newindex", function(...)
  167. local t, k, v = ...
  168.  
  169. if t == cam and k == "CFrame" and events.UserCFrameChanged then
  170. events.UserCFrameChanged:Fire(Enum.UserCFrame.Head, CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  171. end
  172.  
  173. nind(t, k, v)
  174. end)
  175.  
  176.  
  177.  
  178. uis.InputBegan:connect(function(i) -- also least favorite
  179. if headset then
  180. if i.UserInputType == Enum.UserInputType.Keyboard then
  181. body(i.KeyCode)
  182. elseif i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.MouseButton2 or i.UserInputType == Enum.UserInputType.MouseButton3 then
  183. body(i.UserInputType)
  184. end
  185. end
  186. end)
  187.  
  188. uis.InputEnded:connect(function(i)
  189. if headset then
  190. if i.UserInputType == Enum.UserInputType.Keyboard then
  191. body(i.KeyCode, -1)
  192. elseif i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.MouseButton2 or i.UserInputType == Enum.UserInputType.MouseButton3 then
  193. body(i.UserInputType, -1)
  194. end
  195. end
  196. end)
  197.  
  198. rs:BindToRenderStep(game:GetService("HttpService"):GenerateGUID(), Enum.RenderPriority.Camera.Value - 1, function() -- at least it works
  199. if events.UserCFrameChanged and headset then
  200. local mpos = uis:GetMouseLocation()
  201.  
  202. local cursordir = cam:ViewportPointToRay(mpos.x, mpos.y).Direction
  203.  
  204. body.lHand[3] = body.lHand[1] and math.clamp(body.lHand[3] + 0.05, 0, 1) or body.lHand[3] > 0 and math.clamp(body.lHand[3] - 0.05, 0, 1) or body.lHand[3]
  205. body.rHand[3] = body.rHand[1] and math.clamp(body.rHand[3] + 0.05, 0, 1) or body.rHand[3] > 0 and math.clamp(body.rHand[3] - 0.05, 0, 1) or body.rHand[3]
  206.  
  207. local theta = math.acos(Vector3.new(-1, 0, 0):Dot((cam.CFrame.LookVector * Vector3.new(1, 0, 1)).unit))
  208.  
  209. theta = cam.CFrame.LookVector.z > 0 and (2 * math.pi) - theta or theta
  210.  
  211.  
  212. body.lHand[2] = CFrame.new(-math.cos(theta - (math.pi / 4)), -0.5, -math.sin(theta - (math.pi / 4)))
  213. body.rHand[2] = CFrame.new(-math.cos(theta + (math.pi / 4)), -0.5, -math.sin(theta + (math.pi / 4)))
  214.  
  215. local lcf = ((body.lHand[2]):lerp(CFrame.new(cursordir * 100 / cam.HeadScale), body.lHand[3]))
  216. local rcf = ((body.rHand[2]):lerp(CFrame.new(cursordir * 100 / cam.HeadScale), body.rHand[3]))
  217.  
  218. events.UserCFrameChanged:Fire(Enum.UserCFrame.LeftHand, lcf * CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  219. events.UserCFrameChanged:Fire(Enum.UserCFrame.RightHand, rcf * CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  220. end
  221. end)
  222.  
  223. p = plyrs.LocalPlayer or (function()
  224. plyrs:GetPropertyChangedSignal("LocalPlayer"):wait() -- this doesnt return anything for some reason??
  225. return plyrs.LocalPlayer
  226. end)()
Add Comment
Please, Sign In to add comment