Hi! So I want to make a guided missile that has proportional guidence (when the computer sort of “predicts” where the target will be and guides the missile to that predicted position).
However, I am having a hard time trying to get this to work properly. I assume the problem is in the formula that is used to guide the missile to its target.
I have tried many times to fix this by changing the formula in different ways, but
no dice.
Here is a video showing the problem
The green box is the predicted position.
And here is my script:
local missilepart = workspace.missile
local missilespeed = 100
local target = workspace.etget
local debugbox = workspace.debug
missilepart.VectorForce.Force = Vector3.new(0, missilepart:GetMass() * workspace.Gravity, 0)
while true do
local TTI = (target.Position - missilepart.Position) / missilespeed
local predictpos = target.Position + target.AssemblyLinearVelocity * TTI
debugbox.Position = predictpos
missilepart.CFrame = CFrame.new(missilepart.Position, predictpos)
missilepart.AssemblyLinearVelocity = missilepart.CFrame.LookVector * missilespeed
task.wait(0.01)
end
I think what you’re looking for is something called “Augmented Proportional Navigation”, which is a more accurate (but more complex) algorithm for the missile. (Formula in python: Link) Think of my formula as more of a direct lead calculation, which is still effective to an extent, but only in certain situations.
Another solution to your problem (which I am interpreting as the missile not perfectly rotating in a lead the target, subsequently lagging behind) could be to simply increase the speed of the missile by using a constant instead of the formula of the missile’s mass times the force of gravity.
I managed to get it working a few hours before your reply
Here is a video:
And here is how the new script looks:
local missilepart = workspace.missile
local missilespeed = 30
task.wait(3)
local target = workspace.VectorMan_Real.HumanoidRootPart
local debugbox = workspace.debug
missilepart.AssemblyLinearVelocity = missilepart.CFrame.LookVector * missilespeed
missilepart.VectorForce.Force = Vector3.new(0, missilepart:GetMass() * workspace.Gravity, 0)
while true do
local TTI = (target.Position - missilepart.Position).Magnitude / missilepart.AssemblyLinearVelocity.Magnitude
local predictpos = target.Position + target.AssemblyLinearVelocity * TTI
debugbox.Position = predictpos
missilepart.CFrame = CFrame.lookAt(missilepart.Position, predictpos)
missilepart.AssemblyLinearVelocity = missilepart.CFrame.LookVector * missilespeed
task.wait(0.01)
end
Also I have stumbled upon that post you linked in your reply and I tried to replicate that script in studio, and I was succesful, but it just doesn’t fit in roblox’s engine and has many flaws.
Anyway, I thank you a lot for trying to help me and I wish your 2025 will be a great year.