anphu04

ROBLOX Free Camera script

Jan 2nd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. -- 3/1/2019 free camera script by Valualty --
  2. -- twitter: @Valualty --
  3. SPEEDY_DRIFTY = 0.7 -- studs every 1/60 seconds
  4. x_degree = 1.2 -- degrees every 1/60 seconds
  5. y_degree = 0.8 -- degrees every 1/60 seconds
  6. plr = game.Players.LocalPlayer
  7. repeat
  8.     wait()
  9. until plr.Character
  10. mouse = plr:GetMouse()
  11. cam = workspace.CurrentCamera
  12. hum = plr.Character.Humanoid
  13. oldspeed = hum.WalkSpeed
  14. run = game:GetService('RunService')
  15.  
  16. screensize = cam.ViewportSize
  17.  
  18. w,s,a,d,q,e = false,false,false,false,false,false -- position
  19. rr,rl,ru,rd = false,false,false,false -- rotation
  20. ded = false
  21. tog = true
  22.  
  23. keydown = mouse.KeyDown:Connect(function(key)
  24.     if key == 'w' then w = true end
  25.     if key == 's' then s = true end
  26.     if key == 'a' then a = true end
  27.     if key == 'd' then d = true end
  28.     if key == 'q' then q = true end
  29.     if key == 'e' then e = true end
  30.    
  31.     if hum.Health > 0 then
  32.         if key == string.lower('f') then
  33.             if tog then
  34.                 tog = false
  35.             else
  36.                 tog = true
  37.             end
  38.         end
  39.     end
  40. end)
  41. keyup = mouse.KeyUp:Connect(function(key)
  42.     if key == 'w' then w = false end
  43.     if key == 's' then s = false end
  44.     if key == 'a' then a = false end
  45.     if key == 'd' then d = false end
  46.     if key == 'q' then q = false end
  47.     if key == 'e' then e = false end
  48. end)
  49.  
  50. died = hum.Died:Connect(function()
  51.     ded = true
  52. end)
  53.  
  54. mousemove = mouse.Move:Connect(function()
  55.     x = mouse.X
  56.     y = mouse.Y
  57.     if x / screensize.X <= 0.01 then
  58.         rl = true
  59.     else
  60.         rl = false
  61.     end
  62.     if x / screensize.X >= 0.99 then
  63.         rr = true
  64.     else
  65.         rr = false
  66.     end
  67.     if y / screensize.Y <= 0.05 then
  68.         ru = true
  69.     else
  70.         ru = false
  71.     end
  72.     if y / screensize.Y >= 0.9 then
  73.         rd = true
  74.     else
  75.         rd = false
  76.     end
  77. end)
  78.  
  79. while ded == false do
  80.     if tog == true then
  81.         cam.CameraType = 'Scriptable'
  82.         hum.WalkSpeed = 0
  83.         if w then
  84.             cam.CFrame = cam.CFrame * CFrame.new(0,0,-SPEEDY_DRIFTY)
  85.         end
  86.         if s then
  87.             cam.CFrame = cam.CFrame * CFrame.new(0,0,SPEEDY_DRIFTY)
  88.         end
  89.         if a then
  90.             cam.CFrame = cam.CFrame * CFrame.new(-SPEEDY_DRIFTY,0,0)
  91.         end
  92.         if d then
  93.             cam.CFrame = cam.CFrame * CFrame.new(SPEEDY_DRIFTY,0,0)
  94.         end
  95.         if q then
  96.             cam.CFrame = cam.CFrame * CFrame.new(0,-SPEEDY_DRIFTY,0)
  97.         end
  98.         if e then
  99.             cam.CFrame = cam.CFrame * CFrame.new(0,SPEEDY_DRIFTY,0)
  100.         end
  101.        
  102.         -- WORKS IN FIRST TRY --
  103.         -- rotating is in global --
  104.         if rl then
  105.             camrot = cam.CFrame - cam.CFrame.p
  106.             cam.CFrame = CFrame.new(cam.CFrame.p) * CFrame.Angles(0, math.rad(x_degree), 0) * camrot
  107.         end
  108.         if rr then
  109.             camrot = cam.CFrame - cam.CFrame.p
  110.             cam.CFrame = CFrame.new(cam.CFrame.p) * CFrame.Angles(0, math.rad(-x_degree), 0) * camrot
  111.         end
  112.         -- rotating x can't be in global --
  113.         if ru then
  114.             cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(y_degree), 0, 0)
  115.         end
  116.         if rd then
  117.             cam.CFrame = cam.CFrame * CFrame.Angles(math.rad(-y_degree), 0, 0)
  118.         end
  119.     else
  120.         hum.WalkSpeed = oldspeed
  121.         cam.CameraType = 'Custom'
  122.         cam.CameraSubject = hum
  123.     end
  124.     run.RenderStepped:Wait()
  125. end
  126. keydown:Disconnect()
  127. keyup:Disconnect()
  128. died:Disconnect()
  129. mousemove:Disconnect()
  130. cam.CameraType = 'Custom'
  131. cam.CameraSubject = hum
Add Comment
Please, Sign In to add comment