So I’m trying to make a SAM System and im on the missile launch part and with a lot of research I have came to conclusion Proportional Navigation is my answer but after reading for long I still dont get it
here is my script:
local Main = Launcher.MainRotator
local target
local Range = 300
local MaxMissiles = 6
local RemainingMissiles = MaxMissiles
local MissilePrefab = game.ReplicatedStorage.Missile -- Assuming you have a Missile part in ReplicatedStorage
local function FindTarget()
local closestTarget = nil
local closestDistance = Range
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") and v.Parent ~= Launcher and v.Position.Magnitude <= Range then
if v:GetAttribute("AirPlane") and v:GetAttribute("Team") ~= Launcher:GetAttribute("Team") then
local distance = (v.Position - Main.Position).Magnitude
if distance < closestDistance then
closestTarget = v
closestDistance = distance
end
end
end
end
return closestTarget
end
local function GuideSam()
local newTarget = FindTarget()
if newTarget then
target = newTarget
local aimdist = ((Main.Position-target.Position).Magnitude)/Range
local targetpredictedposition=target.Position+(target.Velocity*aimdist)
Main.CFrame = CFrame.lookAt(Main.Position,targetpredictedposition)
end
end
local function LaunchMissile()
if target and RemainingMissiles > 0 then
RemainingMissiles -= 1
end
end
local function RefillMissiles()
RemainingMissiles = MaxMissiles
end
while true do
task.wait(0.1)
GuideSam()
LaunchMissile()
if RemainingMissiles == 0 then
print("ranout")
end
end```
I would prefer if you could explain it