_G.ReactionTime = 0.035 -- delay before diving (good for not making it obvious)
_G.DiveKey = Enum.KeyCode.E -- ur ingame dive key
_G.AutoDiveKey = Enum.KeyCode.LeftControl -- what button u need to hold
repeat task.wait() until workspace:FindFirstChild("Ball")
local UserInputService = game:GetService("UserInputService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Marker = Instance.new("Part")
Marker.Name = "Marker"
Marker.Size = Vector3.new(2, 2, 2)
Marker.Shape = Enum.PartType.Ball
Marker.BrickColor = BrickColor.new("Bright violet")
Marker.CanCollide = false
Marker.Anchored = true
Marker.Parent = workspace
Marker.Transparency = 1
Marker.Material = Enum.Material.Neon
local Beams = {}
local function getPlayerTorsoHeight()
local character = Players.LocalPlayer and Players.LocalPlayer.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
return humanoid.HipHeight * 2
end
end
return 2
end
local function rotateTorsoTowards(targetPosition)
local player = Players.LocalPlayer
if not player or not player.Character then return end
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
local direction = (Vector3.new(targetPosition.X, humanoidRootPart.Position.Y, targetPosition.Z) - humanoidRootPart.Position).unit
local forwardVector = humanoidRootPart.CFrame.LookVector
local angle = math.deg(math.acos(forwardVector:Dot(direction)))
local crossProduct = forwardVector:Cross(direction)
local turnDirection = if crossProduct.Y > 0 then 1 else -1
local allowedAngles = {0, 45, 90, 135, 180}
local closestAllowedAngle = 0
for _, allowedAngle in ipairs(allowedAngles) do
if math.abs(angle - allowedAngle) < math.abs(angle - closestAllowedAngle) then
closestAllowedAngle = allowedAngle
end
end
local maxTurn = math.rad(closestAllowedAngle) * turnDirection
local newCFrame = humanoidRootPart.CFrame * CFrame.Angles(0, maxTurn, 0)
humanoidRootPart.CFrame = newCFrame
end
local function getClosestBeam()
local player = Players.LocalPlayer
if not player or not player.Character then return nil end
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return nil end
local closestBeam = nil
local minDistance = math.huge
for _, beam in pairs(Beams) do
local distance = (humanoidRootPart.Position - beam.Position).Magnitude
if distance < minDistance then
minDistance = distance
closestBeam = beam
end
end
if closestBeam and math.abs(closestBeam.Position.X - humanoidRootPart.Position.X) < 1 and math.abs(closestBeam.Position.Z - humanoidRootPart.Position.Z) < 1 then
return nil
end
return closestBeam
end
local function PHYSICS_STUFF(velocity, position)
local acceleration = -workspace.Gravity
local timeToLand = (-velocity.y - math.sqrt(velocity.y * velocity.y - 4 * 0.5 * acceleration * position.y)) / (2 * 0.5 * acceleration)
local horizontalVelocity = Vector3.new(velocity.x, 0, velocity.z)
local landingPosition = position + horizontalVelocity * timeToLand + Vector3.new(0, -position.y, 0)
return landingPosition
end
local lastActionTime = 0
local actionCooldown = 3
RunService:BindToRenderStep("DiveTowards", Enum.RenderPriority.Camera.Value, function()
if game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):GetState() == Enum.HumanoidStateType.Freefall then
return
end
if not UserInputService:IsKeyDown(_G.AutoDiveKey) then
return
end
local currentTime = tick()
local closestBeam = getClosestBeam()
if not closestBeam then
return
end
if closestBeam:FindFirstChild("Velocity").Value.Magnitude < 50 then
return
end
local magnitude = (closestBeam.Position - game.Players.LocalPlayer.Character.PrimaryPart.Position).Magnitude
if magnitude > 0 and magnitude < 6 then
if currentTime - lastActionTime < actionCooldown then
return
end
lastActionTime = currentTime
task.wait(_G.ReactionTime)
local Mouse = game.Players.LocalPlayer:GetMouse()
VirtualInputManager:SendMouseButtonEvent(Mouse.X, Mouse.Y, 0, true, game, 1)
VirtualInputManager:SendMouseButtonEvent(Mouse.X, Mouse.Y, 0, false, game, 1)
task.wait(_G.ReactionTime)
elseif magnitude > 6 and magnitude < 20 then
if currentTime - lastActionTime < actionCooldown then
return
end
lastActionTime = currentTime
task.wait(_G.ReactionTime)
VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.LeftShift, false, game)
rotateTorsoTowards(closestBeam.Position + Vector3.new(0, getPlayerTorsoHeight(), 0))
VirtualInputManager:SendKeyEvent(true, _G.DiveKey, false, game)
VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.LeftShift, false, game)
else
return
end
end)
RunService:BindToRenderStep("VisualizeLandingPosition", Enum.RenderPriority.Camera.Value, function()
Marker.Transparency = 1
for _, beam in pairs(Beams) do
if beam and beam.Parent then
beam:Destroy()
end
end
Beams = {}
for _, ballModel in ipairs(workspace:GetChildren()) do
if ballModel:IsA("Model") and ballModel.Name == "Ball" then
local ball = ballModel:FindFirstChild("BallPart")
if ball then
local initialVelocity = ballModel.Velocity
local landingPosition = PHYSICS_STUFF(initialVelocity.Value, ball.Position)
Marker.CFrame = CFrame.new(landingPosition)
local BeamPart = Instance.new("Part")
BeamPart.Name = "Beam"
BeamPart.Size = Vector3.new(0.5, getPlayerTorsoHeight(), 0.5)
BeamPart.BrickColor = BrickColor.new("Bright blue")
BeamPart.CanCollide = false
BeamPart.Anchored = true
BeamPart.Parent = workspace
BeamPart.Material = Enum.Material.Neon
BeamPart.Transparency = 1
BeamPart.CFrame = CFrame.new(landingPosition + Vector3.new(0, BeamPart.Size.Y / 2, 0))
local velocity = Instance.new("Vector3Value")
velocity.Name = "Velocity"
velocity.Value = initialVelocity.Value
velocity.Parent = BeamPart
table.insert(Beams, BeamPart)
end
end
end
end)
Comments
No comments yet
Be the first to share your thoughts!