Advertisement
CoolDocterWho

Untitled

Feb 28th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. local Player = game:GetService("Players").LocalPlayer
  2. local ControllerService = game:GetService("ControllerService")
  3. local InputService = game:GetService("UserInputService")
  4. local RenderStepped = game:GetService("RunService").RenderStepped
  5. local ControllerSensitivity = 3
  6.  
  7. repeat wait() until Player.Character ~= nil
  8.  
  9. local Char = Player.Character
  10. local Torso = Char:WaitForChild("HumanoidRootPart")
  11. local Humanoid = Char:WaitForChild("Humanoid")
  12. local GamepadEnabled = InputService.GamepadEnabled
  13. local Inputs = {}
  14. local Thumb1Pos = Vector2.new(0,0)
  15.  
  16. function Connected()
  17. print("connected, bruh")
  18. GamepadEnabled = true
  19. end
  20.  
  21. function CheckConnected()
  22. GamepadEnabled = not GamepadEnabled -- Like that?
  23. end
  24.  
  25. function Disconnected()
  26. print("nooo") -- wot, why? Just because you're using two functions.
  27. GamepadEnabled = false --//Ugly method lel.
  28. end
  29.  
  30. function InputBegan(Input)
  31. if GamepadEnabled then
  32. print(Input.KeyCode) -- We need to start by seeing what input it's getting.
  33. Inputs[Input.KeyCode] = Input
  34. while Inputs[Input.KeyCode] ~= nil do
  35. if Input.KeyCode == Enum.KeyCode.ButtonA then
  36. Humanoid.Jump = true
  37. elseif Input.KeyCode == Enum.KeyCode.ButtonX then -- testing
  38. --Humanoid.Parent:BreakJoints()
  39. end
  40. wait(0.1)
  41. end
  42. end
  43. end
  44.  
  45. function InputChanged(Input)
  46. if Input.KeyCode == Enum.KeyCode.Thumbstick1 or Input.KeyCode == Enum.KeyCode.Thumbstick2 then
  47. Inputs[Input.KeyCode] = Input
  48. end
  49. end
  50.  
  51. function InputEnded(Input)
  52. Inputs[Input.KeyCode] = nil
  53. if Input.KeyCode == Enum.KeyCode.Thumbstick1 then
  54. Humanoid:MoveTo(Torso.Position,Workspace.Terrain)
  55. end
  56. end
  57.  
  58. InputService.GamepadConnected:connect(Connected)
  59. InputService.GamepadDisconnected:connect(Disconnected)
  60. InputService.InputBegan:connect(InputBegan)
  61. InputService.InputChanged:connect(InputChanged)
  62. InputService.InputEnded:connect(InputEnded)
  63.  
  64. while true do
  65. for i,v in pairs(Inputs) do
  66. if v.KeyCode == Enum.KeyCode.Thumbstick2 then
  67. local Dis = (Torso.Position-Workspace.CurrentCamera.CoordinateFrame.p).Magnitude
  68. local CFr = Workspace.CurrentCamera.CoordinateFrame*CFrame.new(0,0,-Dis)
  69. local CFr2 = CFrame.new(Vector3.new(Workspace.CurrentCamera.CoordinateFrame.X,CFr.Y,Workspace.CurrentCamera.CoordinateFrame.Z),CFr.p)
  70. CFr2 = CFrame.new(CFr.p)*(CFr2-(CFr2.p))
  71. local X = math.deg((CFr:toObjectSpace(CFr2):toEulerAnglesXYZ()))
  72. local Ratio = 1
  73. if X > 0 and X < 90 then
  74. Ratio = 1-(X/90)
  75. elseif X < 0 and X > -90 then
  76. Ratio = 1-(X/-90)
  77. end
  78. Ratio = Ratio*2
  79. if Ratio > 1 then
  80. Ratio = 1
  81. end
  82. local New = Workspace.CurrentCamera.CoordinateFrame*CFrame.Angles(math.rad(v.Position.Y*(ControllerSensitivity)),-math.rad(v.Position.X*(ControllerSensitivity*Ratio)),0)*CFrame.new(0,0,-Dis)
  83. if X >= 75 and X <= 90 and v.Position.Y < 0 then
  84. New = Workspace.CurrentCamera.CoordinateFrame*CFrame.Angles(0,-math.rad(v.Position.X*(ControllerSensitivity*Ratio)),0)*CFrame.new(0,0,-Dis)
  85. elseif X >= -90 and X <= -75 and v.Position.Y > 0 then
  86. New = Workspace.CurrentCamera.CoordinateFrame*CFrame.Angles(0,-math.rad(v.Position.X*(ControllerSensitivity*Ratio)),0)*CFrame.new(0,0,-Dis)
  87. end
  88. Workspace.CurrentCamera.Focus = New
  89. elseif v.KeyCode == Enum.KeyCode.Thumbstick1 then
  90. local Dir = Vector3.new(v.Position.X,0,-v.Position.Y)
  91. local NewDir = Workspace.CurrentCamera.CoordinateFrame:vectorToWorldSpace(Dir).unit*100
  92. Humanoid:MoveTo((Workspace.CurrentCamera.CoordinateFrame+NewDir).p,Workspace.Terrain)
  93. end
  94. end
  95. RenderStepped:wait()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement