Advertisement
AnonymousJG179

Locker Missile PVP 3.0

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