Advertisement
Guest User

Untitled

a guest
May 25th, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local Camera = workspace.CurrentCamera
  3.  
  4. local defaultFOV = 70
  5. local zoomedInFOV = 25
  6. local extraZoomedFOV = 5
  7. local zoomSpeed = 0.2
  8. local sensitivitySpeed = 0.1
  9.  
  10. local defaultSensitivity = UserInputService.MouseDeltaSensitivity
  11. local zoomedSensitivity = 0.5
  12. local extraZoomedSensitivity = 0.2
  13.  
  14. local zoomLevel = 0
  15.  
  16. local function smoothZoom(targetFOV)
  17. local currentFOV = Camera.FieldOfView
  18. while math.abs(currentFOV - targetFOV) > 0.1 do
  19. currentFOV = currentFOV + (targetFOV - currentFOV) * zoomSpeed
  20. Camera.FieldOfView = currentFOV
  21. task.wait()
  22. end
  23. Camera.FieldOfView = targetFOV
  24. end
  25.  
  26. local function smoothSensitivity(targetSensitivity)
  27. local currentSensitivity = UserInputService.MouseDeltaSensitivity
  28. while math.abs(currentSensitivity - targetSensitivity) > 0.01 do
  29. currentSensitivity = currentSensitivity + (targetSensitivity - currentSensitivity) * sensitivitySpeed
  30. UserInputService.MouseDeltaSensitivity = currentSensitivity
  31. task.wait()
  32. end
  33. UserInputService.MouseDeltaSensitivity = targetSensitivity
  34. end
  35.  
  36. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  37. if not gameProcessed and input.KeyCode == Enum.KeyCode.E then
  38. zoomLevel = (zoomLevel + 1) % 3
  39.  
  40. local targetFOV, targetSensitivity
  41.  
  42. if zoomLevel == 0 then
  43. targetFOV = defaultFOV
  44. targetSensitivity = defaultSensitivity
  45. elseif zoomLevel == 1 then
  46. targetFOV = zoomedInFOV
  47. targetSensitivity = zoomedSensitivity
  48. elseif zoomLevel == 2 then
  49. targetFOV = extraZoomedFOV
  50. targetSensitivity = extraZoomedSensitivity
  51. end
  52.  
  53. task.spawn(smoothZoom, targetFOV)
  54. task.spawn(smoothSensitivity, targetSensitivity)
  55. end
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement