Advertisement
AnonymousJG179

Locker Missile 3.0

Aug 4th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. -- Toggle Lock-on and Player Movement Prediction Script for Roblox
  2.  
  3. local UserInputService = game:GetService("UserInputService")
  4. local Players = game:GetService("Players")
  5. local RunService = game:GetService("RunService")
  6. local player = Players.LocalPlayer
  7. local camera = game.Workspace.CurrentCamera
  8. local lockedPlayer = nil
  9. local isLockedOn = false
  10. local isPredictingMovement = false
  11. local isSpectating = false
  12.  
  13. -- Function to find the nearest player
  14. local function findNearestPlayer()
  15. local nearestPlayer = nil
  16. local minDistance = math.huge
  17. local playerPosition = camera.CFrame.Position
  18.  
  19. for _, otherPlayer in pairs(Players:GetPlayers()) do
  20. if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  21. local distance = (otherPlayer.Character.HumanoidRootPart.Position - playerPosition).Magnitude
  22. if distance < minDistance then
  23. minDistance = distance
  24. nearestPlayer = otherPlayer
  25. end
  26. end
  27. end
  28.  
  29. return nearestPlayer
  30. end
  31.  
  32. -- Function to update camera position towards target player
  33. local function updateCameraPosition(target)
  34. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  35. local targetPosition = target.Character.HumanoidRootPart.Position
  36. camera.CFrame = CFrame.new(camera.CFrame.p, targetPosition)
  37. end
  38. end
  39.  
  40. -- Function to predict player movement
  41. local function predictPlayerMovement(target)
  42. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  43. local rootPart = target.Character.HumanoidRootPart
  44. local currentPosition = rootPart.Position
  45. local currentVelocity = rootPart.Velocity
  46.  
  47. -- Improved prediction logic
  48. local distance = (currentPosition - camera.CFrame.Position).Magnitude
  49. local predictionTime = math.clamp(distance / 50, 0.1, 2) -- Adjust the divisor for tuning
  50. local predictedPosition = currentPosition + currentVelocity * predictionTime
  51.  
  52. -- Smooth prediction by averaging current and predicted positions
  53. local smoothFactor = 0.8 -- Adjust for smoother transitions
  54. local finalPosition = currentPosition:Lerp(predictedPosition, smoothFactor)
  55.  
  56. camera.CFrame = CFrame.new(camera.CFrame.p, finalPosition)
  57. end
  58. end
  59.  
  60. -- Function to spectate the locked player
  61. local function spectatePlayer(target)
  62. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  63. camera.CameraSubject = target.Character.HumanoidRootPart
  64. end
  65. end
  66.  
  67. -- Function to handle key press
  68. local function onKeyPress(input)
  69. if input.KeyCode == Enum.KeyCode.Equals then
  70. isLockedOn = not isLockedOn
  71. if isLockedOn then
  72. lockedPlayer = findNearestPlayer()
  73. end
  74. elseif input.KeyCode == Enum.KeyCode.Z then
  75. isPredictingMovement = not isPredictingMovement
  76. elseif input.KeyCode == Enum.KeyCode.P then
  77. if isLockedOn and lockedPlayer then
  78. isSpectating = not isSpectating
  79. if not isSpectating then
  80. camera.CameraSubject = player.Character.HumanoidRootPart
  81. end
  82. end
  83. end
  84. end
  85.  
  86. -- Connect the key press function to the UserInputService
  87. UserInputService.InputBegan:Connect(onKeyPress)
  88.  
  89. -- Main loop to update camera position
  90. RunService.RenderStepped:Connect(function()
  91. if isLockedOn and lockedPlayer and lockedPlayer.Character and lockedPlayer.Character:FindFirstChild("HumanoidRootPart") then
  92. if isSpectating then
  93. spectatePlayer(lockedPlayer)
  94. if isPredictingMovement then
  95. predictPlayerMovement(lockedPlayer)
  96. end
  97. elseif isPredictingMovement then
  98. predictPlayerMovement(lockedPlayer)
  99. else
  100. updateCameraPosition(lockedPlayer)
  101. end
  102. end
  103. end)
  104.  
  105. -- Check if the locked player or the player who executed the script dies
  106. player.Character.Humanoid.Died:Connect(function()
  107. lockedPlayer = nil
  108. isLockedOn = false
  109. isSpectating = false
  110. camera.CameraSubject = player.Character.HumanoidRootPart
  111. end)
  112.  
  113. Players.PlayerRemoving:Connect(function(removedPlayer)
  114. if lockedPlayer == removedPlayer then
  115. lockedPlayer = nil
  116. isLockedOn = false
  117. isSpectating = false
  118. camera.CameraSubject = player.Character.HumanoidRootPart
  119. end
  120. end)
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement