Advertisement
Savageannoyingnoob

Roblox naval warfare aimbot physics script

Apr 9th, 2024 (edited)
2,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | Gaming | 0 0
  1. local LocalPlayer = game:GetService("Players").LocalPlayer
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local Camera = workspace.CurrentCamera
  5. local Mouse = LocalPlayer:GetMouse()
  6. local target, offset
  7. local antiGravity = 196.2
  8.  
  9. function getAngles(origin, aimPos, aimVelocity, speed)
  10.     local tolerance = 1e-5
  11.     local aimVector = CFrame.lookAt(origin, aimPos).LookVector
  12.     local cosAngle = aimVector:Dot(aimVelocity.Unit)
  13.     local v = speed
  14.     local g = workspace.Gravity - antiGravity
  15.     local initialGuess = (aimPos - origin).Magnitude / (speed - (aimVelocity.Magnitude * cosAngle))
  16.    
  17.     if initialGuess < 0 or initialGuess ~= initialGuess then
  18.         return nil
  19.     end
  20.    
  21.     local d = aimPos - origin
  22.    
  23.     local t = initialGuess
  24.     for _ = 1, 100 do
  25.         local rt = math.sqrt((d.X + aimVelocity.X * t)^2 + (d.Z + aimVelocity.Z * t)^2)
  26.         local st = math.sqrt(v^4 - g * (g * rt^2 + 2 * (d.Y + aimVelocity.Y * t) * v^2))
  27.  
  28.         if st < 0 then
  29.             return nil
  30.         end
  31.  
  32.         local thetat = math.atan((v^2 - st) / (g * rt))
  33.         local ft = (rt / (v * math.cos(thetat))) - t
  34.        
  35.         if math.abs(ft) <= tolerance then
  36.             local displacement = (aimPos + (aimVelocity * t)) - origin
  37.             local horizontalAngle = math.atan2(displacement.X, displacement.Z)
  38.             local verticalAngle = thetat
  39.             local xzDisplacement = rt
  40.             return horizontalAngle + math.rad(180), verticalAngle, xzDisplacement, t
  41.         end
  42.        
  43.         local rPrime = ((d.X + aimVelocity.X * t) * aimVelocity.X + (d.Z + aimVelocity.Z * t) * aimVelocity.Z) / rt
  44.         local sPrime = (-g * (g * rt * rPrime + aimVelocity.Y * v^2)) / st
  45.         local thetaPrime = (-sPrime * rt - (v^2 - st) * rPrime) / (g * rt^3 + (v^2 - st)^2)
  46.         local cost, sint = math.cos(thetat), math.sin(thetat)
  47.         local dft = ((rPrime / (v * cost)) + (rt * sint * thetaPrime) / (v * cost^2)) - 1
  48.         if dft == nil or dft == 0 then
  49.             break
  50.         end
  51.        
  52.         t = t - ft / dft
  53.     end
  54. end
  55.  
  56. local function changeBulletGravity(input, _gameProcessed)
  57.     if input.KeyCode == Enum.KeyCode.Two then
  58.         antiGravity = 163.5
  59.         return
  60.     end
  61.     if input.KeyCode == Enum.KeyCode.Three then
  62.         antiGravity = 196.2
  63.         return
  64.     end
  65. end
  66.  
  67. local function setTarget(input, _gameProcessed)
  68.     if input.UserInputType ~= Enum.UserInputType.MouseButton3 then
  69.         return
  70.     end
  71.  
  72.     if not (target and offset) then
  73.         if not (Mouse.Target and Mouse.Hit) then
  74.             return
  75.         end
  76.         target = Mouse.Target
  77.         offset = target.Position - Mouse.Hit.Position
  78.     else
  79.         target = nil
  80.         offset = nil
  81.     end
  82. end
  83.  
  84. local function aimTarget()
  85.     if not (target and target.Parent) then return end
  86.  
  87.     local origin = LocalPlayer.Character.HumanoidRootPart.Position
  88.     local horizontalAngle, verticalAngle, dist = getAngles(origin, target.Position - offset, target.Velocity, 800)
  89.     if not dist then return end
  90.  
  91.     local direction = CFrame.fromOrientation(verticalAngle, horizontalAngle, 0).LookVector * dist
  92.     local pos, _ = Camera:WorldToViewportPoint(origin + direction)
  93.     local loc = UserInputService:GetMouseLocation()
  94.     mousemoverel(pos.X - loc.X, pos.Y - loc.Y)
  95. end
  96.  
  97. RunService:BindToRenderStep('AimAt', Enum.RenderPriority.Camera.Value + 1, aimTarget)
  98. UserInputService.InputBegan:Connect(changeBulletGravity)
  99. UserInputService.InputBegan:Connect(setTarget)
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement