local RunService = game:GetService("RunService") local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") task.wait(3) local lp = Players.LocalPlayer local camera = workspace.CurrentCamera local playerGui = lp:WaitForChild("PlayerGui") -- CONFIG local FLY_SPEED = 50 -- flight speed (studs/s) local targetAnimationId = "rbxassetid://84784070267976" local KNOCKBACK_DISTANCE = 2 -- studs pushed backwards at the start local KNOCKBACK_TIME = 0.15 -- how long the knockback lasts (seconds) local KNOCKBACK_RANGE = 8 -- max distance to a humanoid to trigger knockback local HOMING_RANGE = 5 -- max distance to a humanoid to redirect the flight local HOMING_STRENGTH = 0.3 -- 0 = no homing, 1 = straight to target local AUTO_AIM_ENABLED = true -- true = face the target, false = keep facing the camera local AUTO_AIM_TURN_SPEED = 6 -- how fast the character turns toward the target (higher = snappier) local AUTO_AIM_DURATION = 0.5 -- how long auto-aim stays active after the animation starts (seconds) -- END CONFIG local aimEnabled = false local activeTrack = nil local humanoid = nil local hrp = nil local linearVelocity = nil local alignOrientation = nil local attachment = nil local knockbackUntil = 0 local knockbackVelocity = Vector3.zero local currentFacing = Vector3.zero local autoAimUntil = 0 local screenGui = Instance.new("ScreenGui") screenGui.Name = "AimToggleGui" screenGui.ResetOnSpawn = false screenGui.Parent = playerGui local statusLabel = Instance.new("TextLabel") statusLabel.Name = "StatusLabel" statusLabel.Size = UDim2.new(0, 150, 0, 40) statusLabel.Position = UDim2.new(1, -160, 1, -50) statusLabel.BackgroundColor3 = Color3.fromRGB(50, 200, 50) statusLabel.BackgroundTransparency = 0.7 statusLabel.TextColor3 = Color3.fromRGB(255, 255, 255) statusLabel.TextSize = 14 statusLabel.Text = "" statusLabel.BorderSizePixel = 0 statusLabel.Visible = false statusLabel.Parent = screenGui local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 8) corner.Parent = statusLabel local function isShiftLockOn() return UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter end local function getLookDirection() return camera.CFrame.LookVector end local function createFlyParts(character) hrp = character:WaitForChild("HumanoidRootPart") humanoid = character:WaitForChild("Humanoid") attachment = Instance.new("Attachment") attachment.Name = "FlyAttachment" attachment.Parent = hrp linearVelocity = Instance.new("LinearVelocity") linearVelocity.Name = "FlyVelocity" linearVelocity.Attachment0 = attachment linearVelocity.MaxForce = math.huge linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World linearVelocity.Enabled = false linearVelocity.Parent = hrp alignOrientation = Instance.new("AlignOrientation") alignOrientation.Name = "FlyAlign" alignOrientation.Attachment0 = attachment alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment alignOrientation.MaxTorque = math.huge alignOrientation.Responsiveness = 50 alignOrientation.Enabled = false alignOrientation.Parent = hrp end local function getNearbyHumanoidRoot(range) local character = lp.Character local myHrp = character and character:FindFirstChild("HumanoidRootPart") if not myHrp then return nil end local params = OverlapParams.new() params.FilterType = Enum.RaycastFilterType.Exclude params.FilterDescendantsInstances = {character} local closestRoot = nil local closestDist = range local parts = workspace:GetPartBoundsInRadius(myHrp.Position, range, params) for _, part in ipairs(parts) do local model = part:FindFirstAncestorOfClass("Model") local targetHum = model and model:FindFirstChildOfClass("Humanoid") local targetRoot = model and model:FindFirstChild("HumanoidRootPart") if targetHum and targetRoot and targetHum.Health > 0 then local dist = (targetRoot.Position - myHrp.Position).Magnitude if dist < closestDist then closestDist = dist closestRoot = targetRoot end end end return closestRoot end local function isHumanoidNearby() return getNearbyHumanoidRoot(KNOCKBACK_RANGE) ~= nil end local function startAim(track) activeTrack = track aimEnabled = true humanoid.PlatformStand = true humanoid.AutoRotate = false -- stops the default/shift lock rotation from fighting the flight linearVelocity.Enabled = true alignOrientation.Enabled = true statusLabel.Visible = true statusLabel.Text = isShiftLockOn() and "Flying (Shift Lock)" or "Flying!" currentFacing = getLookDirection() autoAimUntil = os.clock() + AUTO_AIM_DURATION -- knockback only if a humanoid is nearby if isHumanoidNearby() then local look = getLookDirection() knockbackVelocity = -look * (KNOCKBACK_DISTANCE / KNOCKBACK_TIME) knockbackUntil = os.clock() + KNOCKBACK_TIME else knockbackUntil = 0 end end local function stopAim() aimEnabled = false activeTrack = nil statusLabel.Visible = false if humanoid then humanoid.PlatformStand = false humanoid.AutoRotate = true end if linearVelocity then linearVelocity.Enabled = false end if alignOrientation then alignOrientation.Enabled = false end end local function setupCharacter(character) aimEnabled = false activeTrack = nil knockbackUntil = 0 autoAimUntil = 0 statusLabel.Visible = false createFlyParts(character) humanoid.AnimationPlayed:Connect(function(track) if track.Animation.AnimationId == targetAnimationId then startAim(track) end end) end if lp.Character then setupCharacter(lp.Character) end lp.CharacterAdded:Connect(setupCharacter) RunService.Heartbeat:Connect(function(dt) if activeTrack and (not activeTrack.IsPlaying or activeTrack.TimePosition >= activeTrack.Length) then stopAim() end if not aimEnabled then return end -- keep the label correct if shift lock is toggled mid-flight statusLabel.Text = isShiftLockOn() and "Flying (Shift Lock)" or "Flying!" local look = getLookDirection() if os.clock() < knockbackUntil then linearVelocity.VectorVelocity = knockbackVelocity currentFacing = look alignOrientation.CFrame = CFrame.lookAt(Vector3.zero, look) return end local autoAimActive = AUTO_AIM_ENABLED and os.clock() < autoAimUntil local direction = look local desiredFacing = look local targetRoot = getNearbyHumanoidRoot(HOMING_RANGE) if targetRoot and hrp then local offset = targetRoot.Position - hrp.Position local dist = offset.Magnitude if dist > 0.01 then local toTarget = offset.Unit direction = look:Lerp(toTarget, HOMING_STRENGTH).Unit if autoAimActive then local closeness = math.clamp(1 - dist / HOMING_RANGE, 0, 1) desiredFacing = look:Lerp(toTarget, closeness) end end end local alpha = math.clamp(AUTO_AIM_TURN_SPEED * dt, 0, 1) currentFacing = currentFacing:Lerp(desiredFacing, alpha) if currentFacing.Magnitude < 0.01 then currentFacing = look end currentFacing = currentFacing.Unit linearVelocity.VectorVelocity = direction * FLY_SPEED alignOrientation.CFrame = CFrame.lookAt(Vector3.zero, currentFacing) end) RunService.RenderStepped:Connect(function() if not aimEnabled or not isShiftLockOn() then return end local character = lp.Character local root = character and character:FindFirstChild("HumanoidRootPart") if not root then return end -- override the shift lock rotation with our facing, keeping the current position root.CFrame = CFrame.lookAt(root.Position, root.Position + currentFacing) end)