local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local Camera = workspace.CurrentCamera local Players = game:GetService("Players") local LocalPlayer = Players.LocalPlayer local Vehicles = workspace:WaitForChild("Vehicles") -- --- [ CONFIGURATION ] --- local AimKey = Enum.UserInputType.MouseButton2 -- กดปุ่มขวาค้างเพื่อล็อกเป้า local Smoothness = 0.15 -- ความสมูท (0.1 = ลื่นมาก, 1 = ล็อกทันที) local AimDistance = 5000 -- ระยะล็อกสูงสุด (เมตร) local TargetName = "AircraftBot" -- หรือ "ShipBot" -- ------------------------- local Locking = false local CurrentTarget = nil -- ฟังก์ชันหาเป้าหมายที่ใกล้ "เป้าเล็ง" ที่สุด local function getClosestTarget() local closest = nil local shortestMouseDist = math.huge for _, bot in ipairs(Vehicles:GetChildren()) do if (bot.Name == "AircraftBot" or bot.Name == "ShipBot") then local model = bot:FindFirstChild("Model") local targetPart = model and model:FindFirstChildWhichIsA("BasePart") if targetPart then -- ตรวจสอบว่าอยู่ในระยะ และอยู่ในหน้าจอไหม local screenPos, onScreen = Camera:WorldToViewportPoint(targetPart.Position) local dist = (LocalPlayer.Character.HumanoidRootPart.Position - targetPart.Position).Magnitude if onScreen and dist < AimDistance then -- คำนวณความห่างจากกลางหน้าจอ (FOV-based Targeting) local mousePos = UserInputService:GetMouseLocation() local mouseDist = (Vector2.new(screenPos.X, screenPos.Y) - mousePos).Magnitude if mouseDist < shortestMouseDist then shortestMouseDist = mouseDist closest = targetPart end end end end end return closest end -- ตรวจสอบการกดปุ่ม UserInputService.InputBegan:Connect(function(input) if input.UserInputType == AimKey then Locking = true end end) UserInputService.InputEnded:Connect(function(input) if input.UserInputType == AimKey then Locking = false CurrentTarget = nil end end) -- ทำงานทุกเฟรม (RenderStepped) RunService.RenderStepped:Connect(function() if Locking then CurrentTarget = getClosestTarget() if CurrentTarget then -- คำนวณทิศทาง local lookAt = CFrame.new(Camera.CFrame.Position, CurrentTarget.Position) -- ปรับกล้องแบบสมูท (Interpolation) Camera.CFrame = Camera.CFrame:Lerp(lookAt, Smoothness) end end end) print("Tactical Aimlock Loaded! (Hold Right-Click to aim)")