Proportional Navigation?

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

Any help would be appreciated :slight_smile:

Hi! I see that in your block of code that guides the missile (aimdist and target prediction stuff), you switched around some variables and numbers. I am not sure exactly how the guidance is being a problem, but I’ll paste my code here.

		local TTI = (target.Position - lookpart.Position) / lookpart.AssemblyLinearVelocity                   
               --{{lookpart is the missile}}-
		local hitPos = target.Position + target.AssemblyLinearVelocity * TTI
		lookpart.CFrame = CFrame.new(lookpart.Position, hitPos)
		lookpart.LinearVelocity.VectorVelocity = lookpart.CFrame.LookVector * maxspeed

So the TTI is the time to impact, where TTI is the distance from the missile and target divided by the missile’s speed. The hit position (hitPos) or where the missile is going to head towards is received by taking the target’s position, adding the target’s speed to it, and multiplying it by the TTI. The missile’s CFrame is also constantly updated so that it is always turning to the new hitPos received. The missile’s speed isn’t relevant to the guidance, but the missile should always be faster than the target to be effective. (keep in mind this should all be in a loop as long as the target is active)
(Sometimes the missile freaks out and misses, so I too am still trying to fix it.)

Best of luck to you!

1 Like

Well this is a suprise I kinda quit on this but I’ll be sure to come back to it now. :+1:

1 Like

Hi there, if you are returning to it, I can suggest this article for a better understanding: (GameDev) Introduction to Proportional Navigation (Part I) blog - blahdy - ModDB

1 Like