AALTTz

free cam

Oct 22nd, 2022
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. ToggleKey = Enum.KeyCode.C
  2. SprintKey = Enum.KeyCode.Tab
  3.  
  4. localPlayer = game.Players.LocalPlayer
  5.  
  6. Camera = game.Workspace.CurrentCamera
  7. Mouse = localPlayer:GetMouse()
  8.  
  9. UserInputService = game:GetService("UserInputService")
  10.  
  11.  
  12. movePosition = Vector2.new(0,0)
  13. moveDirection = Vector3.new(0,0,0)
  14.  
  15. targetMovePosition = movePosition
  16.  
  17. Y_Sensitivity = 300;
  18. X_Sensitivity = 300;
  19.  
  20. lastRightButtonDown = Vector2.new(0,0)
  21. rightMouseButtonDown = false
  22.  
  23. targetFOV = 70
  24.  
  25. sprinting = false;
  26. sprintingSpeed = 3;
  27.  
  28. keysDown = {}
  29.  
  30. moveKeys = {
  31. [Enum.KeyCode.D] = Vector3.new(1,0,0),
  32. [Enum.KeyCode.A] = Vector3.new(-1,0,0),
  33. [Enum.KeyCode.S] = Vector3.new(0,0,1),
  34. [Enum.KeyCode.W] = Vector3.new(0,0,-1),
  35. [Enum.KeyCode.E] = Vector3.new(0,1,0),
  36. [Enum.KeyCode.Q] = Vector3.new(0,-1,0)
  37. }
  38.  
  39. Tween = function(a,b,t)
  40. if t == 1 then
  41. return b
  42. else
  43. if tonumber(a) then
  44. return a * (1-t) + (b*t)
  45. else
  46. return a:Lerp(b,t);
  47. end
  48. end
  49. end
  50.  
  51. ClampVector3 = function(x,min,max)
  52.  
  53. return
  54. Vector3.new(
  55. math.clamp(x.X,min.X,max.X),
  56. math.clamp(x.Y,min.Y,max.Y),
  57. math.clamp(x.Z,min.Z,max.Z)
  58. )
  59.  
  60. end
  61.  
  62.  
  63. UserInputService.InputChanged:connect(function(inputObject)
  64. if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
  65. movePosition = movePosition + Vector2.new(inputObject.Delta.x,inputObject.Delta.y)
  66. end
  67. end)
  68.  
  69. CalculateMovement = function()
  70. local newMovement = Vector3.new(0,0,0)
  71. for i,v in pairs(keysDown) do
  72. newMovement = newMovement + (moveKeys[i] or Vector3.new(0,0,0))
  73. end
  74. return newMovement
  75. end
  76.  
  77. Round = function(num, numDecimalPlaces)
  78. return math.floor((num/numDecimalPlaces) + .5)*numDecimalPlaces
  79. end
  80.  
  81. Input = function(input,gameProcessed)
  82. if moveKeys[input.KeyCode] then
  83. if input.UserInputState == Enum.UserInputState.Begin then
  84. keysDown[input.KeyCode] = true
  85. elseif input.UserInputState == Enum.UserInputState.End then
  86. keysDown[input.KeyCode] = nil
  87. end
  88. else
  89. if input.UserInputState == Enum.UserInputState.Begin then
  90. print(input.KeyCode)
  91. if input.UserInputType == Enum.UserInputType.MouseButton2 then
  92. rightMouseButtonDown = true
  93. lastRightButtonDown = Vector2.new(Mouse.X,Mouse.Y)
  94. UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
  95. elseif input.KeyCode == Enum.KeyCode.Z then
  96. targetFOV = 20
  97. elseif input.KeyCode == SprintKey then
  98. sprinting = true
  99. end
  100. else
  101. if input.UserInputType == Enum.UserInputType.MouseButton2 then
  102. rightMouseButtonDown = false
  103. UserInputService.MouseBehavior = Enum.MouseBehavior.Default
  104. elseif input.KeyCode == Enum.KeyCode.Z then
  105. targetFOV = 70
  106. elseif input.KeyCode == SprintKey then
  107. sprinting = false
  108. end
  109. end
  110. end
  111. end
  112.  
  113. Mouse.WheelForward:connect(function()
  114. Camera.CoordinateFrame = Camera.CoordinateFrame * CFrame.new(0,0,-5)
  115. end)
  116.  
  117. Mouse.WheelBackward:connect(function()
  118. Camera.CoordinateFrame = Camera.CoordinateFrame * CFrame.new(-0,0,5)
  119. end)
  120.  
  121. UserInputService.InputBegan:connect(Input)
  122. UserInputService.InputEnded:connect(Input)
  123.  
  124. local Toggled = false
  125. game:GetService("UserInputService").InputBegan:connect(function(inputObject)
  126. if inputObject.KeyCode == ToggleKey then
  127. Toggled = not Toggled
  128. if Toggled then
  129. Camera.CameraType = Enum.CameraType.Scriptable
  130. game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = true
  131. game.Players.LocalPlayer.Character.Humanoid.PlatformStand = true
  132. else
  133. game.Players.LocalPlayer.Character.Humanoid.PlatformStand = false
  134. game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false
  135. game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
  136. game.Workspace.CurrentCamera.CameraType = "Custom"
  137. end
  138. end
  139. end)
  140.  
  141.  
  142. game:GetService("RunService").RenderStepped:Connect(function()
  143. if Toggled then
  144. local mouseTarget = Mouse.Hit
  145.  
  146. targetMovePosition = movePosition
  147. Camera.CoordinateFrame = CFrame.new(Camera.CoordinateFrame.p) * CFrame.fromEulerAnglesYXZ(-targetMovePosition.Y/Y_Sensitivity ,-targetMovePosition.X/X_Sensitivity, 0) * CFrame.new(CalculateMovement() * ((({[true]=sprintingSpeed})[sprinting]) or .5) )
  148. Camera.FieldOfView = Tween(Camera.FieldOfView,targetFOV,.5)
  149. if rightMouseButtonDown then
  150. UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
  151. movePosition = movePosition - (lastRightButtonDown - Vector2.new(Mouse.X,Mouse.Y))
  152. lastRightButtonDown = Vector2.new(Mouse.X,Mouse.Y)
  153. end
  154. end
  155. end)
Add Comment
Please, Sign In to add comment