Advertisement
Guest User

Roblox Smooth First Person Script

a guest
Oct 28th, 2024
9,998
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | Gaming | 0 0
  1. --[[ Scripted by coolcapidog
  2. Channel ->> https://www.youtube.com/c/coolcapidog
  3. Don't change anything except you know how to script.
  4. You can change the settings but you shouldn't change anything except settings.
  5. ]]
  6. ----------------------------------- Settings
  7. CanToggleMouse = {allowed = true; activationkey = Enum.KeyCode.F;}
  8. CanViewBody = true
  9. Sensitivity = 0.6
  10. Smoothness = 0.05
  11. FieldOfView = 120
  12. HeadOffset = CFrame.new(0,0.7,0)
  13. ----------------------------------- Settings
  14.  
  15. repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
  16. local runService = game:GetService("RunService")
  17. local input = game:GetService("UserInputService")
  18. local players = game:GetService("Players")
  19.  
  20. local cam = game.Workspace.CurrentCamera
  21. local player = players.LocalPlayer
  22. local m = player:GetMouse()
  23. m.Icon = "http://www.roblox.com/asset/?id=569021388" -- replaces mouse icon
  24. local character = player.Character or player.CharacterAdded:wait()
  25. local human = character.Humanoid
  26. local humanoidpart = character.HumanoidRootPart
  27.  
  28. local head = character:WaitForChild("Head")
  29. local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p
  30. local AngleX,TargetAngleX = 0,0
  31. local AngleY,TargetAngleY = 0,0
  32.  
  33. local running = true
  34. local freemouse = false
  35. local defFOV = FieldOfView
  36.  
  37. local w, a, s, d, lshift = false, false, false, false, false
  38.  
  39. local easingtime = 0.1 --0~1
  40. local walkspeeds = {
  41. enabled = true;
  42. walkingspeed = 16;
  43. backwardsspeed = 10;
  44. sidewaysspeed = 15;
  45. diagonalspeed = 16;
  46. runningspeed = 25;
  47. runningFOV= 85;}
  48.  
  49. function updatechar()
  50. for _, v in pairs(character:GetChildren())do
  51. if CanViewBody then
  52. if v.Name == 'Head' then
  53. v.LocalTransparencyModifier = 1
  54. v.CanCollide = false
  55. v.face.LocalTransparencyModifier = 1
  56. end
  57. else
  58. if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
  59. v.LocalTransparencyModifier = 1
  60. v.CanCollide = false
  61. end
  62. end
  63. if v:IsA'Accessory' then
  64. v:FindFirstChild('Handle').LocalTransparencyModifier = 1
  65. v:FindFirstChild('Handle').CanCollide = false
  66. end
  67. if v:IsA'Hat' then
  68. v:FindFirstChild('Handle').LocalTransparencyModifier = 1
  69. v:FindFirstChild('Handle').CanCollide = false
  70. end
  71. end
  72. end
  73.  
  74. function lerp(a, b, t)
  75. return a * (1-t) + (b*t)
  76. end
  77. input.InputChanged:connect(function(inputObject)
  78. if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
  79. local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
  80.  
  81. local X = TargetAngleX - delta.y
  82. TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
  83. TargetAngleY = (TargetAngleY - delta.x) %360
  84. end
  85. end)
  86.  
  87. input.InputBegan:connect(function(inputObject)
  88. if inputObject.UserInputType == Enum.UserInputType.Keyboard then
  89. if inputObject.KeyCode == CanToggleMouse.activationkey then
  90. if CanToggleMouse.allowed and freemouse == false then
  91. freemouse = true
  92. else
  93. freemouse = false
  94. end
  95. end
  96. end
  97. if inputObject.UserInputType == Enum.UserInputType.Keyboard then
  98. if inputObject.KeyCode == Enum.KeyCode.W then
  99. w = true
  100. end
  101. if inputObject.KeyCode == Enum.KeyCode.A then
  102. a = true
  103. end
  104. if inputObject.KeyCode == Enum.KeyCode.S then
  105. s = true
  106. end
  107. if inputObject.KeyCode == Enum.KeyCode.D then
  108. d = true
  109. end
  110. if inputObject.KeyCode == Enum.KeyCode.LeftShift then
  111. lshift = true
  112. end
  113. end
  114. end)
  115.  
  116. input.InputEnded:connect(function(inputObject)
  117. if inputObject.UserInputType == Enum.UserInputType.Keyboard then
  118. if inputObject.KeyCode == Enum.KeyCode.W then
  119. w = false
  120. end
  121. if inputObject.KeyCode == Enum.KeyCode.A then
  122. a = false
  123. end
  124. if inputObject.KeyCode == Enum.KeyCode.S then
  125. s = false
  126. end
  127. if inputObject.KeyCode == Enum.KeyCode.D then
  128. d = false
  129. end
  130. if inputObject.KeyCode == Enum.KeyCode.LeftShift then
  131. lshift = false
  132. end
  133. end
  134. end)
  135.  
  136. runService.RenderStepped:connect(function()
  137. if running then
  138. updatechar()
  139. CamPos = CamPos + (TargetCamPos - CamPos) *0.28
  140. AngleX = AngleX + (TargetAngleX - AngleX) *0.35
  141. local dist = TargetAngleY - AngleY
  142. dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
  143. AngleY = (AngleY + dist *0.35) %360
  144. cam.CameraType = Enum.CameraType.Scriptable
  145. cam.CoordinateFrame = CFrame.new(head.Position)
  146. * CFrame.Angles(0,math.rad(AngleY),0)
  147. * CFrame.Angles(math.rad(AngleX),0,0)
  148. * HeadOffset
  149. humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
  150. else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
  151. end
  152. if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
  153. running = false
  154. else
  155. running = true
  156. if freemouse == true then
  157. game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
  158. else
  159. game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
  160. end
  161. end
  162. if not CanToggleMouse.allowed then
  163. freemouse = false
  164. end
  165. cam.FieldOfView = FieldOfView
  166. if walkspeeds.enabled then
  167. if w and s then return end
  168. if w and not lshift then
  169. FieldOfView = lerp(FieldOfView, defFOV,easingtime)
  170. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.walkingspeed,easingtime)
  171. elseif w and a then
  172. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.diagonalspeed,easingtime)
  173. elseif w and d then
  174. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.diagonalspeed,easingtime)
  175. elseif s then
  176. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed,easingtime)
  177. elseif s and a then
  178. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed - (walkspeeds.diagonalspeed - walkspeeds.backwardsspeed),easingtime)
  179. elseif s and d then
  180. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.backwardsspeed - (walkspeeds.diagonalspeed - walkspeeds.backwardsspeed),easingtime)
  181. elseif d then
  182. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.sidewaysspeed,easingtime)
  183. elseif a then
  184. human.WalkSpeed = lerp(human.WalkSpeed,walkspeeds.sidewaysspeed,easingtime)
  185. end
  186. if lshift and w then
  187. FieldOfView = lerp(FieldOfView, walkspeeds.runningFOV,easingtime)
  188. human.WalkSpeed = lerp(human.WalkSpeed,human.WalkSpeed + (walkspeeds.runningspeed - human.WalkSpeed),easingtime)
  189. end
  190. end
  191. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement