Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. --Shortening
  2. local char = game.Players.LocalPlayer.Character
  3. local camera = workspace.CurrentCamera
  4.  
  5. --Services
  6. local uis = game:GetService("UserInputService")
  7. local rs = game:GetService("RunService")
  8.  
  9. --Settings
  10. local shiftDown = false
  11. local lookingAtPart = false
  12. local point
  13.  
  14. --Input
  15. uis.InputBegan:Connect(function(io, gpe)
  16. if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
  17. shiftDown = true
  18. end
  19. end)
  20. uis.InputEnded:Connect(function(io, gpe)
  21. if io.KeyCode == Enum.KeyCode.LeftShift and not gpe then
  22. shiftDown = false
  23. end
  24. end)
  25.  
  26. --Lock on closest player
  27. local increment = 1
  28. rs.RenderStepped:Connect(function()
  29. --Closest player
  30. local plr
  31. local otherPlayers = {}
  32. for i,v in pairs(game.Players:GetPlayers()) do
  33. if v.Character ~= char then
  34. table.insert(otherPlayers, v)
  35. end
  36. end
  37. for i,v in pairs(otherPlayers) do
  38. local currentDistance = (v.Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
  39. local pastDistance = (otherPlayers[i-1].Character.Head.CFrame.Position - char.Head.CFrame.Position).Magnitude
  40. if i == 1 then
  41. plr = v
  42. elseif currentDistance > pastDistance then
  43. plr = v
  44. end
  45. end
  46. if plr then point = plr.Character.Head end
  47.  
  48. if point then
  49. --lookingAtPart
  50. local part, hitPos = workspace:FindPartOnRay(Ray.new(camera.CFrame.Position, camera.CFrame.LookVector * 500), char)
  51. if part == point then
  52. lookingAtPart = true
  53. else
  54. lookingAtPart = false
  55. end
  56.  
  57. --Lerping
  58. if shiftDown then
  59. if increment < 101 and not lookingAtPart then
  60. camera.CFrame = camera.CFrame:Lerp(CFrame.new(camera.CFrame.Position, point.CFrame.Position), increment/100)
  61. increment = increment + 2
  62. else
  63. camera.CFrame = CFrame.new(camera.CFrame.Position, point.CFrame.Position)
  64. end
  65. else
  66. increment = 1
  67. end
  68. end
  69. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement