Advertisement
TheSovietRat

VR ROBLOX

Jan 18th, 2020
42,290
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.85 KB | None | 0 0
  1. loadstring(game:GetObjects("rbxassetid://4480871791")[1].Source)()
  2.  
  3.  
  4.  
  5. local VRService = game:GetService("VRService")
  6.  
  7. local character = workspace.CloneCharacter
  8.  
  9. local HeadDisplay = Instance.new("Part", workspace)
  10. HeadDisplay.Anchored = true
  11. HeadDisplay.CanCollide = false
  12. HeadDisplay.Size = Vector3.new(0.5,0.5,0.5)
  13. HeadDisplay.Transparency = 1
  14. HeadDisplay.Color = Color3.fromRGB(125,125,255)
  15. HeadDisplay.TopSurface = Enum.SurfaceType.Smooth
  16. HeadDisplay.BottomSurface = Enum.SurfaceType.Smooth
  17. HeadDisplay.Name = "HeadDisplay"
  18.  
  19.  
  20. local leftHandDisplay = Instance.new("Part", workspace)
  21. leftHandDisplay.Anchored = true
  22. leftHandDisplay.CanCollide = false
  23. leftHandDisplay.Size = Vector3.new(0.5,0.5,0.5)
  24. leftHandDisplay.Transparency = 1
  25. leftHandDisplay.Color = Color3.fromRGB(125,125,255)
  26. leftHandDisplay.TopSurface = Enum.SurfaceType.Smooth
  27. leftHandDisplay.BottomSurface = Enum.SurfaceType.Smooth
  28. leftHandDisplay.Name = "leftHandDisplay"
  29.  
  30. local rightHandDisplay = Instance.new("Part", workspace)
  31. rightHandDisplay.Anchored = true
  32. rightHandDisplay.CanCollide = false
  33. rightHandDisplay.Size = Vector3.new(0.5,0.5,0.5)
  34. rightHandDisplay.Transparency = 1
  35. rightHandDisplay.Color = Color3.fromRGB(255,125,125)
  36. rightHandDisplay.TopSurface = Enum.SurfaceType.Smooth
  37. rightHandDisplay.BottomSurface = Enum.SurfaceType.Smooth
  38. rightHandDisplay.Name = "rightHandDisplay"
  39.  
  40. for i,v in next, workspace.CloneCharacter:GetChildren() do
  41. if v:IsA('Accessory') then
  42. v:Destroy()
  43. end
  44. end
  45.  
  46. spawn(function()
  47. VRService.UserCFrameChanged:Connect(function()
  48. local character = workspace.CloneCharacter
  49.  
  50. HeadScale = 1
  51. Cam = workspace.CurrentCamera
  52. Cam.HeadScale = HeadScale
  53.  
  54. local cfRH = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
  55. local RightHandCFrame = (Cam.CFrame*CFrame.new(cfRH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfRH:ToEulerAnglesXYZ())
  56. rightHandDisplay.CFrame = RightHandCFrame
  57.  
  58. local cfLH = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
  59. local LeftHandCFrame = (Cam.CFrame*CFrame.new(cfLH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfLH:ToEulerAnglesXYZ())
  60. leftHandDisplay.CFrame = LeftHandCFrame
  61.  
  62. local cfH = VRService:GetUserCFrame(Enum.UserCFrame.Head)
  63. local HeadCFrame = (Cam.CFrame*CFrame.new(cfH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfH:ToEulerAnglesXYZ())
  64. HeadDisplay.CFrame = HeadCFrame
  65.  
  66.  
  67. character["Head"].Orientation = HeadDisplay.Orientation
  68. character["Head"].Position = HeadDisplay.Position
  69. character["Left Arm"].Orientation = leftHandDisplay.Orientation + Vector3.new(45,0,0)
  70. character["Left Arm"].Position = leftHandDisplay.Position
  71. character["Right Arm"].Orientation = rightHandDisplay.Orientation + Vector3.new(45,0,0)
  72. character["Right Arm"].Position = rightHandDisplay.Position
  73. end)
  74. end)
  75.  
  76. spawn(function()
  77. ------------------------------------------------------------------------
  78. -- Freecam
  79. -- Cinematic free camera for spectating and video production.
  80. ------------------------------------------------------------------------
  81.  
  82. local pi = math.pi
  83. local abs = math.abs
  84. local clamp = math.clamp
  85. local exp = math.exp
  86. local rad = math.rad
  87. local sign = math.sign
  88. local sqrt = math.sqrt
  89. local tan = math.tan
  90.  
  91. local ContextActionService = game:GetService("ContextActionService")
  92. local Players = game:GetService("Players")
  93. local RunService = game:GetService("RunService")
  94. local StarterGui = game:GetService("StarterGui")
  95. local UserInputService = game:GetService("UserInputService")
  96. local Workspace = game:GetService("Workspace")
  97.  
  98. local LocalPlayer = Players.LocalPlayer
  99. if not LocalPlayer then
  100. Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
  101. LocalPlayer = Players.LocalPlayer
  102. end
  103.  
  104. local Camera = Workspace.CurrentCamera
  105. Workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function()
  106. local newCamera = Workspace.CurrentCamera
  107. if newCamera then
  108. Camera = newCamera
  109. end
  110. end)
  111.  
  112. ------------------------------------------------------------------------
  113.  
  114. local TOGGLE_INPUT_PRIORITY = Enum.ContextActionPriority.Low.Value
  115. local INPUT_PRIORITY = Enum.ContextActionPriority.High.Value
  116. local FREECAM_MACRO_KB = {}
  117.  
  118. local NAV_GAIN = Vector3.new(1, 1, 1)*64
  119. local PAN_GAIN = Vector2.new(0.75, 1)*8
  120. local FOV_GAIN = 300
  121.  
  122. local PITCH_LIMIT = rad(90)
  123.  
  124. local VEL_STIFFNESS = 1.5
  125. local PAN_STIFFNESS = 1.0
  126. local FOV_STIFFNESS = 4.0
  127.  
  128. ------------------------------------------------------------------------
  129.  
  130. local Spring = {} do
  131. Spring.__index = Spring
  132.  
  133. function Spring.new(freq, pos)
  134. local self = setmetatable({}, Spring)
  135. self.f = freq
  136. self.p = pos
  137. self.v = pos*0
  138. return self
  139. end
  140.  
  141. function Spring:Update(dt, goal)
  142. local f = self.f*2*pi
  143. local p0 = self.p
  144. local v0 = self.v
  145.  
  146. local offset = goal - p0
  147. local decay = exp(-f*dt)
  148.  
  149. local p1 = goal + (v0*dt - offset*(f*dt + 1))*decay
  150. local v1 = (f*dt*(offset*f - v0) + v0)*decay
  151.  
  152. self.p = p1
  153. self.v = v1
  154.  
  155. return p1
  156. end
  157.  
  158. function Spring:Reset(pos)
  159. self.p = pos
  160. self.v = pos*0
  161. end
  162. end
  163.  
  164. ------------------------------------------------------------------------
  165.  
  166. local cameraPos = Vector3.new()
  167. local cameraRot = Vector2.new()
  168. local cameraFov = 0
  169.  
  170. local velSpring = Spring.new(VEL_STIFFNESS, Vector3.new())
  171. local panSpring = Spring.new(PAN_STIFFNESS, Vector2.new())
  172. local fovSpring = Spring.new(FOV_STIFFNESS, 0)
  173.  
  174. ------------------------------------------------------------------------
  175.  
  176. local Input = {} do
  177. local thumbstickCurve do
  178. local K_CURVATURE = 2.0
  179. local K_DEADZONE = 0.15
  180.  
  181. local function fCurve(x)
  182. return (exp(K_CURVATURE*x) - 1)/(exp(K_CURVATURE) - 1)
  183. end
  184.  
  185. local function fDeadzone(x)
  186. return fCurve((x - K_DEADZONE)/(1 - K_DEADZONE))
  187. end
  188.  
  189. function thumbstickCurve(x)
  190. return sign(x)*clamp(fDeadzone(abs(x)), 0, 1)
  191. end
  192. end
  193.  
  194. local gamepad = {
  195. ButtonX = 0,
  196. ButtonY = 0,
  197. DPadDown = 0,
  198. DPadUp = 0,
  199. ButtonL2 = 0,
  200. ButtonR2 = 0,
  201. Thumbstick1 = Vector2.new(),
  202. Thumbstick2 = Vector2.new(),
  203. }
  204.  
  205. local keyboard = {
  206. W = 0,
  207. A = 0,
  208. S = 0,
  209. D = 0,
  210. E = 0,
  211. Q = 0,
  212. U = 0,
  213. H = 0,
  214. J = 0,
  215. K = 0,
  216. I = 0,
  217. Y = 0,
  218. Up = 0,
  219. Down = 0,
  220. LeftShift = 0,
  221. RightShift = 0,
  222. }
  223.  
  224. local mouse = {
  225. Delta = Vector2.new(),
  226. MouseWheel = 0,
  227. }
  228.  
  229. local NAV_GAMEPAD_SPEED = Vector3.new(1, 1, 1)
  230. local NAV_KEYBOARD_SPEED = Vector3.new(1, 1, 1)
  231. local PAN_MOUSE_SPEED = Vector2.new(1, 1)*(pi/64)
  232. local PAN_GAMEPAD_SPEED = Vector2.new(1, 1)*(pi/8)
  233. local FOV_WHEEL_SPEED = 1.0
  234. local FOV_GAMEPAD_SPEED = 0.25
  235. local NAV_ADJ_SPEED = 0.75
  236. local NAV_SHIFT_MUL = 0.25
  237.  
  238. local navSpeed = 1
  239.  
  240. function Input.Vel(dt)
  241. navSpeed = clamp(navSpeed + dt*(keyboard.Up - keyboard.Down)*NAV_ADJ_SPEED, 0.01, 4)
  242.  
  243. local kGamepad = Vector3.new(
  244. thumbstickCurve(gamepad.Thumbstick1.x),
  245. thumbstickCurve(gamepad.ButtonR2) - thumbstickCurve(gamepad.ButtonL2),
  246. thumbstickCurve(-gamepad.Thumbstick1.y)
  247. )*NAV_GAMEPAD_SPEED
  248.  
  249. local kKeyboard = Vector3.new(
  250. keyboard.D - keyboard.A + keyboard.K - keyboard.H,
  251. keyboard.E - keyboard.Q + keyboard.I - keyboard.Y,
  252. keyboard.S - keyboard.W + keyboard.J - keyboard.U
  253. )*NAV_KEYBOARD_SPEED
  254.  
  255. local shift = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
  256.  
  257. return (kGamepad + kKeyboard)*(navSpeed*(shift and NAV_SHIFT_MUL or 1))
  258. end
  259.  
  260. function Input.Pan(dt)
  261. local kGamepad = Vector2.new(
  262. thumbstickCurve(gamepad.Thumbstick2.y),
  263. thumbstickCurve(-gamepad.Thumbstick2.x)
  264. )*PAN_GAMEPAD_SPEED
  265. local kMouse = mouse.Delta*PAN_MOUSE_SPEED
  266. mouse.Delta = Vector2.new()
  267. return kGamepad + kMouse
  268. end
  269.  
  270. function Input.Fov(dt)
  271. local kGamepad = (gamepad.ButtonX - gamepad.ButtonY)*FOV_GAMEPAD_SPEED
  272. local kMouse = mouse.MouseWheel*FOV_WHEEL_SPEED
  273. mouse.MouseWheel = 0
  274. return kGamepad + kMouse
  275. end
  276.  
  277. do
  278. local function Keypress(action, state, input)
  279. keyboard[input.KeyCode.Name] = state == Enum.UserInputState.Begin and 1 or 0
  280. return Enum.ContextActionResult.Sink
  281. end
  282.  
  283. local function GpButton(action, state, input)
  284. gamepad[input.KeyCode.Name] = state == Enum.UserInputState.Begin and 1 or 0
  285. return Enum.ContextActionResult.Sink
  286. end
  287.  
  288. local function MousePan(action, state, input)
  289. local delta = input.Delta
  290. mouse.Delta = Vector2.new(-delta.y, -delta.x)
  291. return Enum.ContextActionResult.Sink
  292. end
  293.  
  294. local function Thumb(action, state, input)
  295. gamepad[input.KeyCode.Name] = input.Position
  296. return Enum.ContextActionResult.Sink
  297. end
  298.  
  299. local function Trigger(action, state, input)
  300. gamepad[input.KeyCode.Name] = input.Position.z
  301. return Enum.ContextActionResult.Sink
  302. end
  303.  
  304. local function MouseWheel(action, state, input)
  305. mouse[input.UserInputType.Name] = -input.Position.z
  306. return Enum.ContextActionResult.Sink
  307. end
  308.  
  309. local function Zero(t)
  310. for k, v in pairs(t) do
  311. t[k] = v*0
  312. end
  313. end
  314.  
  315. function Input.StartCapture()
  316. ContextActionService:BindActionAtPriority("FreecamKeyboard", Keypress, false, INPUT_PRIORITY,
  317. Enum.KeyCode.W, Enum.KeyCode.U,
  318. Enum.KeyCode.A, Enum.KeyCode.H,
  319. Enum.KeyCode.S, Enum.KeyCode.J,
  320. Enum.KeyCode.D, Enum.KeyCode.K,
  321. Enum.KeyCode.E, Enum.KeyCode.I,
  322. Enum.KeyCode.Q, Enum.KeyCode.Y,
  323. Enum.KeyCode.Up, Enum.KeyCode.Down
  324. )
  325. ContextActionService:BindActionAtPriority("FreecamMousePan", MousePan, false, INPUT_PRIORITY, Enum.UserInputType.MouseMovement)
  326. ContextActionService:BindActionAtPriority("FreecamMouseWheel", MouseWheel, false, INPUT_PRIORITY, Enum.UserInputType.MouseWheel)
  327. ContextActionService:BindActionAtPriority("FreecamGamepadButton", GpButton, false, INPUT_PRIORITY, Enum.KeyCode.ButtonX, Enum.KeyCode.ButtonY)
  328. ContextActionService:BindActionAtPriority("FreecamGamepadTrigger", Trigger, false, INPUT_PRIORITY, Enum.KeyCode.ButtonR2, Enum.KeyCode.ButtonL2)
  329. ContextActionService:BindActionAtPriority("FreecamGamepadThumbstick", Thumb, false, INPUT_PRIORITY, Enum.KeyCode.Thumbstick1, Enum.KeyCode.Thumbstick2)
  330. end
  331.  
  332. function Input.StopCapture()
  333. navSpeed = 1
  334. Zero(gamepad)
  335. Zero(keyboard)
  336. Zero(mouse)
  337. ContextActionService:UnbindAction("FreecamKeyboard")
  338. ContextActionService:UnbindAction("FreecamMousePan")
  339. ContextActionService:UnbindAction("FreecamMouseWheel")
  340. ContextActionService:UnbindAction("FreecamGamepadButton")
  341. ContextActionService:UnbindAction("FreecamGamepadTrigger")
  342. ContextActionService:UnbindAction("FreecamGamepadThumbstick")
  343. end
  344. end
  345. end
  346.  
  347. local function GetFocusDistance(cameraFrame)
  348. local znear = 0.1
  349. local viewport = Camera.ViewportSize
  350. local projy = 2*tan(cameraFov/2)
  351. local projx = viewport.x/viewport.y*projy
  352. local fx = cameraFrame.rightVector
  353. local fy = cameraFrame.upVector
  354. local fz = cameraFrame.lookVector
  355.  
  356. local minVect = Vector3.new()
  357. local minDist = 512
  358.  
  359. for x = 0, 1, 0.5 do
  360. for y = 0, 1, 0.5 do
  361. local cx = (x - 0.5)*projx
  362. local cy = (y - 0.5)*projy
  363. local offset = fx*cx - fy*cy + fz
  364. local origin = cameraFrame.p + offset*znear
  365. local _, hit = Workspace:FindPartOnRay(Ray.new(origin, offset.unit*minDist))
  366. local dist = (hit - origin).magnitude
  367. if minDist > dist then
  368. minDist = dist
  369. minVect = offset.unit
  370. end
  371. end
  372. end
  373.  
  374. return fz:Dot(minVect)*minDist
  375. end
  376.  
  377. ------------------------------------------------------------------------
  378.  
  379. local function StepFreecam(dt)
  380. local vel = velSpring:Update(dt, Input.Vel(dt))
  381. local pan = panSpring:Update(dt, Input.Pan(dt))
  382. local fov = fovSpring:Update(dt, Input.Fov(dt))
  383.  
  384. local zoomFactor = sqrt(tan(rad(70/2))/tan(rad(cameraFov/2)))
  385.  
  386. cameraFov = clamp(cameraFov + fov*FOV_GAIN*(dt/zoomFactor), 1, 120)
  387. cameraRot = cameraRot + pan*PAN_GAIN*(dt/zoomFactor)
  388. cameraRot = Vector2.new(clamp(cameraRot.x, -PITCH_LIMIT, PITCH_LIMIT), cameraRot.y%(2*pi))
  389.  
  390. local cameraCFrame = CFrame.new(cameraPos)*CFrame.fromOrientation(cameraRot.x, cameraRot.y, 0)*CFrame.new(vel*NAV_GAIN*dt)
  391. cameraPos = cameraCFrame.p
  392.  
  393. Camera.CFrame = cameraCFrame
  394. Camera.Focus = cameraCFrame*CFrame.new(0, 0, -GetFocusDistance(cameraCFrame))
  395. Camera.FieldOfView = cameraFov
  396. end
  397.  
  398. ------------------------------------------------------------------------
  399.  
  400. local PlayerState = {} do
  401. local mouseBehavior
  402. local cameraType
  403. local cameraFocus
  404. local cameraCFrame
  405. local cameraFieldOfView
  406. local screenGuis = {}
  407. local coreGuis = {
  408. Backpack = true,
  409. Chat = true,
  410. Health = true,
  411. PlayerList = true,
  412. }
  413. local setCores = {
  414. BadgesNotificationsActive = true,
  415. PointsNotificationsActive = true,
  416. }
  417.  
  418. -- Save state and set up for freecam
  419. function PlayerState.Push()
  420. for name in pairs(coreGuis) do
  421. coreGuis[name] = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType[name])
  422. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], false)
  423. end
  424. for name in pairs(setCores) do
  425. setCores[name] = StarterGui:GetCore(name)
  426. StarterGui:SetCore(name, false)
  427. end
  428. local playergui = LocalPlayer:FindFirstChildOfClass("PlayerGui")
  429. if playergui then
  430. for _, gui in pairs(playergui:GetChildren()) do
  431. if gui:IsA("ScreenGui") and gui.Enabled then
  432. screenGuis[#screenGuis + 1] = gui
  433. gui.Enabled = false
  434. end
  435. end
  436. end
  437.  
  438. cameraFieldOfView = Camera.FieldOfView
  439. Camera.FieldOfView = 70
  440.  
  441. cameraType = Camera.CameraType
  442. Camera.CameraType = Enum.CameraType.Custom
  443.  
  444. cameraCFrame = Camera.CFrame
  445. cameraFocus = Camera.Focus
  446.  
  447. mouseBehavior = UserInputService.MouseBehavior
  448. UserInputService.MouseBehavior = Enum.MouseBehavior.Default
  449. end
  450.  
  451. -- Restore state
  452. function PlayerState.Pop()
  453. for name, isEnabled in pairs(coreGuis) do
  454. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], isEnabled)
  455. end
  456. for name, isEnabled in pairs(setCores) do
  457. StarterGui:SetCore(name, isEnabled)
  458. end
  459. for _, gui in pairs(screenGuis) do
  460. if gui.Parent then
  461. gui.Enabled = true
  462. end
  463. end
  464.  
  465. Camera.FieldOfView = cameraFieldOfView
  466. cameraFieldOfView = nil
  467.  
  468. Camera.CameraType = cameraType
  469. cameraType = nil
  470.  
  471. Camera.CFrame = cameraCFrame
  472. cameraCFrame = nil
  473.  
  474. Camera.Focus = cameraFocus
  475. cameraFocus = nil
  476.  
  477. UserInputService.MouseBehavior = mouseBehavior
  478. mouseBehavior = nil
  479. end
  480. end
  481.  
  482. local function StartFreecam()
  483. local cameraCFrame = Camera.CFrame
  484. cameraRot = Vector2.new(cameraCFrame:toEulerAnglesYXZ())
  485. cameraPos = cameraCFrame.p
  486. cameraFov = Camera.FieldOfView
  487.  
  488. velSpring:Reset(Vector3.new())
  489. panSpring:Reset(Vector2.new())
  490. fovSpring:Reset(0)
  491.  
  492. PlayerState.Push()
  493. RunService:BindToRenderStep("Freecam", Enum.RenderPriority.Camera.Value, StepFreecam)
  494. Input.StartCapture()
  495. end
  496.  
  497. local function StopFreecam()
  498. Input.StopCapture()
  499. RunService:UnbindFromRenderStep("Freecam")
  500. PlayerState.Pop()
  501. end
  502.  
  503. ------------------------------------------------------------------------
  504.  
  505. do
  506. local enabled = true
  507. StartFreecam()
  508.  
  509. local function ToggleFreecam()
  510. if enabled then
  511. StopFreecam()
  512. else
  513. StartFreecam()
  514. end
  515. enabled = not enabled
  516. end
  517.  
  518. local function CheckMacro(macro)
  519. for i = 1, #macro - 1 do
  520. if not UserInputService:IsKeyDown(macro[i]) then
  521. return
  522. end
  523. end
  524. ToggleFreecam()
  525. end
  526.  
  527. local function HandleActivationInput(action, state, input)
  528. if state == Enum.UserInputState.Begin then
  529. if input.KeyCode == FREECAM_MACRO_KB[#FREECAM_MACRO_KB] then
  530. CheckMacro(FREECAM_MACRO_KB)
  531. end
  532. end
  533. return Enum.ContextActionResult.Pass
  534. end
  535.  
  536. ContextActionService:BindActionAtPriority("FreecamToggle", HandleActivationInput, false, TOGGLE_INPUT_PRIORITY, FREECAM_MACRO_KB[#FREECAM_MACRO_KB])
  537. end
  538. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement