Fezezen

CB like camera wobble

Jul 25th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local cam = workspace.CurrentCamera
  3. local UserInputService = game:GetService("UserInputService")
  4. local mouse = player:GetMouse()
  5. local character = player.Character
  6. repeat wait() character = player.Character until character
  7. local head = character:WaitForChild("Head")
  8. local humanoid = character:WaitForChild("Humanoid")
  9.  
  10. local sin = math.sin
  11. local cos = math.cos
  12. local rad = math.rad
  13.  
  14. local CF = CFrame.new
  15. local CFAngles = CFrame.Angles
  16. local wobbleCF = CF()
  17. local zero = CF()
  18. local wobble = 0
  19. local wobbleY = 0
  20. local dir = 1
  21. local dirY = 1
  22.  
  23. local Sensitivity = 5
  24.  
  25. local mouse_V = 0
  26. local mouse_H = 0
  27.  
  28. local MAX_V_UP = rad(80)
  29. local MAX_V_DN = rad(-80)
  30.  
  31. local function constrain(min, max, num)
  32.     return num < min and min or num > max and max or num
  33. end
  34.  
  35. UserInputService.InputChanged:connect(function(input)
  36.     if input.UserInputType == Enum.UserInputType.MouseMovement then
  37.         mouse_V = constrain(MAX_V_DN, MAX_V_UP, mouse_V + rad(input.Delta.Y/Sensitivity))
  38.         mouse_H = mouse_H + rad(input.Delta.x/Sensitivity)
  39.     end
  40. end)
  41.  
  42. local walking = false
  43. local speed = 1
  44.  
  45. humanoid.Running:Connect(function(s)
  46.     if s > 1 then
  47.         speed = s
  48.         walking = true
  49.     else
  50.         walking = false
  51.     end
  52. end)
  53.  
  54. game:GetService("RunService").RenderStepped:connect(function()
  55.     UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
  56.     cam.CameraType = Enum.CameraType.Scriptable    
  57.    
  58.     if walking then
  59.         wobbleCF = wobbleCF:lerp(
  60.             CFAngles(0,0,rad(wobble))
  61.         ,.3)
  62.        
  63.         wobble = wobble + dir*.15*(speed/16)
  64.         if math.abs(wobble) > 2 then
  65.             dir = -dir
  66.         end
  67.         wobbleY = wobbleY + dirY*.3*(speed/16)
  68.         if math.abs(wobbleY) > 4 then
  69.             dirY = -dirY
  70.         end
  71.     else
  72.         wobble = 0
  73.         wobbleY = 0
  74.         wobbleCF = wobbleCF:lerp(zero,.2)
  75.     end
  76.    
  77.     local rotation = CFAngles(0, -mouse_H, 0)
  78.     local rotation2 = CFAngles(-mouse_V, 0, 0)
  79.     local baseCFrame = CF(head.Position)
  80.     local nextCam = baseCFrame * rotation * rotation2 * CF(0,0,-1)
  81.    
  82.     cam.CameraType = Enum.CameraType.Scriptable
  83.     cam:Interpolate(baseCFrame* rotation *wobbleCF,nextCam*CF(0,rad(wobbleY*.1),0),0.01)       
  84.    
  85.     for _, v in pairs(character:GetChildren())do
  86.         if v:IsA'Part' then
  87.                 v.LocalTransparencyModifier = 1
  88.             for _, hat in pairs(character:GetChildren())do
  89.                 if hat:IsA'Accessory' then
  90.                     hat.Handle.LocalTransparencyModifier = 1
  91.                 end
  92.             end
  93.         end
  94.     end
  95. end)
Advertisement
Add Comment
Please, Sign In to add comment